C++ C+中的奇怪行为+;while循环和ifstream

C++ C+中的奇怪行为+;while循环和ifstream,c++,while-loop,fstream,ifstream,C++,While Loop,Fstream,Ifstream,因此,当我从循环中的文件读取输入时,我的函数无法正常工作: ifstream in(inputFileName.c_str()); //input file is a string string word; while (in >> word){ cout << word << endl; //this behaves as it should n prints all words in file test.

因此,当我从循环中的文件读取输入时,我的函数无法正常工作:

ifstream in(inputFileName.c_str());  //input file is a string
    string word;
    while (in >> word){
        cout << word << endl;  //this behaves as it should n prints all words in file
        test.insert(word, 0);       //this function won't insert the words !
    }
。。。。
一切都很好!!这对我来说真的很奇怪,有什么想法会导致这种情况吗?

我觉得问题可能出在您的哈希表类中,其中的
test
就是一个例子

<> P>没有一个很好的理由去做其他的事情,我至少应该考虑使用<代码> STD::unOrdEdEdSt< <代码>代替:

std::ifstream in(inputFilename); // `.c_str()` no longer required in C++11

// read the words into the set
std::unordered_set test {std::istream_iterator<std::string>(in),
                         std::istream_iterator<std::string>()};

// display the unique words:
std::cout << "Unique words:\n";
std::copy(test.begin(), test.end(), 
          std::ostream_iterator<std::string>(std::cout, "\n"));
std::ifstream-in(inputFilename);/`。c_str()`在c++11中不再需要
//把单词读入集合
std::无序集测试{std::istream\u迭代器(in),
std::istream_iterator()};
//显示唯一的单词:

std::cout您的文件包含什么?test的定义是什么?文件有45k个字符串,每行一个。test是哈希表的一种类类型。
std::ifstream in(inputFilename); // `.c_str()` no longer required in C++11

// read the words into the set
std::unordered_set test {std::istream_iterator<std::string>(in),
                         std::istream_iterator<std::string>()};

// display the unique words:
std::cout << "Unique words:\n";
std::copy(test.begin(), test.end(), 
          std::ostream_iterator<std::string>(std::cout, "\n"));