I searched/googled for some time now, but found nothing regarding this problem:
When reading lines from a file with getline(), all tabulators are missing.
A line looks like this:
a b c
(that is: a tabulator b tabulator c)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <string>
#include <iostream>
#include <fstream>
main()
{
std::ifstream file;
file.open("file.txt");
if(! file.is_open())
return 1;
std::string s;
std::getline(file,s); // first line is: "a\tb\tc"
std::cout << s << std::endl; // prints: abc
}
The extracted string only contains the non-tab characters.
Expected result is: "a b c".
With a file with spaces instead of tabulators it works fine, but it should work with tabulators as well, right?
Ok, at least I'm sure now it should work.
Alas, it doesn't.
I run your code and again after the getline() the string contains no tabulators.
Therefore I'm fairly sure there is nothing wrong with the file (since the behaviour is the same whether I apply getline() to the ifstream or to the stringstream).
That produces "tab" twice. As it should, I reckoned.
And now, after altering my code at several lines, it works. Still not sure why and what exactly did make the difference. Will be back to post the solution as soon as I know what it was.