关于C++小白的问题,如图,程序可以编译并运行,但是无法显示文本中的文字 泛型算法也不会显示,为什么?

另外 ,如何在CODEBLOCK设置断点呢?

#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中做输出,输出结果是到文件,你查看运行后的文件就可以知道对不对了。
另外,你程序中没有对文件进行关闭操作。

追问

呃 谢谢回答, 已经解决了 是我对同一个文件同时进行读取和输出了- -

温馨提示:内容为网友见解,仅供参考
第1个回答  2016-09-03
在读的时候,打印出来看看有没有读到 。。。。。。。。。。。追问

读的时候直接把我原来的内容篡改成unsorted text:了。。
然而我这个程序是照着教材COPY下来的。。
这是怎么回事呢

相似回答