程序没结果,帮忙调下

来源:百度知道 编辑:UC知道 时间:2024/05/18 08:31:32
/*
*在文件中写入内容,再把文件中的内容放进list中,
*然后删除list中相同的元素
*PS:没结果,哪位高人帮帮忙,谢谢了
*/
#include <iostream>
#include <list>
#include <fstream>
#include <algorithm>
#include <string>
using namespace std;
int main(int argc,char **argv)
{
fstream inFile;
inFile.open("D:\\123.txt");
if(!inFile)
{
cerr<<"Cannot open input file!"<<endl;
return EXIT_FAILURE;
}
inFile<<"name apple enum name love node "<<endl;
list<string> words;
string word;
while(inFile>>word)
words.push_back(word);
words.sort();
words.unique();
cout<<"unique words:"<<endl;
for(list<string>::iterator iter=words.begin();iter!=words.end();++iter)
cout<<*iter<<" ";
cout<<endl;
inFile.close();
return 0;
}

文件操作的问题
inFile.open("D:\\123.txt", iso::out); //err
if(!inFile)
{
cerr<<"Cannot open input file!"<<endl;
return EXIT_FAILURE;
}
inFile<<"name apple enum name love node "<<endl;
//添加如下两行
inFile.close(); //关闭文件,使缓冲中数据写入文件中
inFile.open("D:\\123.txt", iso::in); //以读方式打开

lz的问题中 哪有这句话?

inFile.open("D:\\123.txt", iso::out); //err
楼上的回答

我的环境 测试代码,语法上没有问题。