例子如下:
#include<iostream>
#include<fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i,j;
cout<<"please input two number"<<endl;
cin>>i>>j;
cout<<"the sum of two number:"<<endl;
cout<<i+j;
return 0;
}
本来程序的输出会在控制台上,进行重定向
方法:
cmd→(拖动文件名到控制台)重定向文件名.exe >>xxx.txt
输入数字:
1 5
结果自动就添加到了xxx.txt中了