I open a file in read only mode, I read a line, and I cannot understand the meaning of the line contents as shown by the debugger:
#include <cctype>
#include <fstream>
#include <iostream>
#include <string>
int main()
{
std::string fidMapPath = "./file.txt";
std::ifstream ifsFidMap(fidMapPath);
if(ifsFidMap.good() == false) {
std::cerr << "Error" << std::endl;
exit(1);
}
std::string line;
while(ifsFidMap.eof() == false)
{
std::getline(ifsFidMap, line);
std::cout << "Line: " << line << std::endl;
}
}
This is the contents of the text file:
; Document title
123;456
123;123
456;456
...
When running, nothing is printed from the line
variable; with the debugger, its contents is equal to "" (empty) before getline()
, and \\000\\000\\000\\000...
after, repeated up to a length of 2411 characters.
What is the meaning of this behavior?
These are my platform details:
P.S.: I tried, as suggested, to move the getline
in the while
argument:
while(std::getline(ifsFidMap, line))
but I still have the same issue.
With the version of GCC I used, 4.8.2, we must explicitly specify if what being compiled is C++11 code with the -std=c++11
compiler option. Otherwise it defaults to C++98.
This applies to GCC versions up to 5.x.