第2个回答 2013-07-30
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void main()
{
//创建文件,输入点内容来测试
string str="Hello World";
ofstream fp;
fp.open("temp.txt");
fp<<str;
fp.close();
//读取文件内容
string temp;
ifstream ftemp;
ftemp.open("temp.txt",ios::in);
ftemp>>temp;
cout<<temp<<' '<<temp<<endl;
ftemp.close();
}本回答被网友采纳