I have a file which contain some numbers, all in one line . I would like to read this file and put this line to a string variable.
So as it contains only one line, the getline()
method should works only once
But It's not the case. It works twice. I notice that first my string_descriptor contains the number (so it's okey) but after getline take another line and this time it's empty but by looking at the debugger the string contains a lot of \O\ like 10 times.
\O\O\O\O\O\O\O\O\O\O\O\O\O\O\O\
And it bothers me because after I'm doing some processing and because of that my app crashs.
So what I'm doing is the following :
fs.open (desc.c_str (), std::ios::in);
string line;
if(!fs.is_open())
{
cout<<"\n Cannot open the text.txt file";
}
else
{
std::string string_descriptor;
while (!fs.eof ())
{
getline( fs , line);
if (line != "" && line.find_first_not_of(' ') != std::string::npos && !line.empty())
{
string_descriptor = line;
std::cout << "String descriptor : " << string_descriptor << std::endl;
}
}
}
So why it happened ? And especially how can I handle that ? I tried to handle that by doing the following but It's still the same :
if (line != "" && line.find_first_not_of(' ') != std::string::npos && !line.empty())
I checked my file and there is no space at the end of the file, so far I know.
Thank you for your help