首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个c++文件有关问题

2013-01-28 
一个c++文件问题includefstreamusing namespace stdifstream fin(input.txt)ofstream fout(output.

一个c++文件问题
include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int main()
{
    int a,b;
    while(fin>>a>>b)  fout << a+b <<"\n";
    return 0;
}

这个东西怎么用的,我写文件里两个数,没运行成功
求指教
[解决办法]
#include <iostream>
#include <fstream>
using namespace std;

int main()
{    
ofstream fout;
fout.open("data.txt");
fout<<"123 456";
fout.close();

ifstream fin;
fin.open("data.txt");
int a,b;
fin>>a>>b;
fin.close();
cout<<a<<"+"<<b<<"="<<a+b<<endl;
}


输出:
123+456=579
请按任意键继续. . .

热点排行
Bad Request.