#include
#include
#include
int main()
{
using namespace std;
ifstream in_stream;
ofstream out_stream;
in_stream.open("infile.txt");
if(in_stream.fail())
{
cout<<"input file opening failed.\n";
exit(1);
}
out_stream.open("outfile.txt");
if(out_stream.fail())
{
cout<<"output file opening failed.\n";
exit(1);
}
int first,second,third;
in_stream>>first>>second>>third;
out_stream<<"The sum of the first 3 \n"
<<"number in infile.dat\n"
<<"is"<<(first+second+third)
<<endl;
in_stream.close();
out_stream.close();
return 0;
}
为什么open函数调用失败了?(语言-c++)
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- a5156520 2022-06-28 14:03关注
需要在程序同目录下新建一个infile.txt的文件,里面存入三个整数,然后程序就会从这个文件读取这三个数,把其他说明信息和这三个数的和写入程序同目录下的outfile.txt文件里面。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改