c++ - vector push_back doesn't work -


i created simple code, push_back function doesn't want work. gives me absolutely different result expected.

here code:

std::vector<std::string> words; std::ifstream infile ("words.txt"); std::string temp; while (std::getline(infile, temp)) {     words.push_back(temp); } (std::size_t = 0; < words.size(); i++) {     std::cout << words[i] << " "; } 

the "words.txt" file contains 4 words:

window tyre give speaker 

the result supposed "window tyre give speaker", me " speaker". problem?

this proved underlying problem:

have tried dumping input file (e.g. hexdump -c or similar) check rogue control sequences such \r might explain behaviour seeing.

your input file might text file dos/windows-like system , might using unix-like system.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -