#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ifstream in_file ("d:\\test.txt");
string word;
vector<string> text;
while (in_file>>word)
text.push_back(word);
in_file.close();
int ix;
for (ix=0;ix<text.size();ix++)
cout << text[ix] << " ";
sort(text.begin(), text.end());
cout << endl;
for (ix=0;ix<text.size();ix++)
cout << text[ix] << " ";
return 0;
}
run result:
we were her pride of ten she named us.
her named of pride she ten us. we were
Process returned 0 (0x0) execution time : 0.004 s
Press any key to continue.
你的问题是什么?
因为你的程序没有向console中做输出,输出结果是到文件,你查看运行后的文件就可以知道对不对了。
另外,你程序中没有对文件进行关闭操作。
追问呃 谢谢回答, 已经解决了 是我对同一个文件同时进行读取和输出了- -