Reading a text file in c++

Posted by Yavuz Karacabey on Stack Overflow See other posts from Stack Overflow or by Yavuz Karacabey
Published on 2012-10-27T16:56:46Z Indexed on 2012/10/27 17:00 UTC
Read the original article Hit count: 281

Filed under:
|
|
string numbers;
string fileName = "text.txt";


ifstream inputFile;
inputFile.open(fileName.c_str(),ios_base::in);
inputFile >> numbers;
inputFile.close();
cout << numbers;

And my text.txt file is:

1    2    3    4    5

basically a set of integers separated by tabs.

The problem is the program only reads the first integer in the text.txt file and ignores the rest for some reason. If I remove the tabs between the integers it works fine, but with tabs between them, it won't work. What causes this? As far as I know it should ignore any white space characters or am I mistaken? If so is there a better way to get each of these numbers from the text file?

© Stack Overflow or respective owner

Related posts about c++

Related posts about text