Reputation: 39
I´ve got a CSV File with some data:
3;13.12.2014;inline;33;434;5434
How do I check if the line ends with '\n'?
I've tried use getline, but getline has got '\n' as delimiter.
Upvotes: 0
Views: 1510
Reputation: 39
Thank you for answer. So, I have construction:
fstream file("sport.csv", fstream::in);
string line;
while(getline(file,line))
{
cout << line << endl;
}
And now, I don´t know, where I put the condition eof() && !fail()
?
Upvotes: 0
Reputation: 153909
This is one case where checking for eof()
would be in order. The input for std::getline
can be terminated by one of three conditions: end of file, a match for the terminator (which will be extracted) , or an attempt to extract more than std::string::max_size()
characters. In practice, the last condition will probably never occur; you'll have encountered an std::bad_alloc
before then. If the terminator has been extracted, then eof()
will still be false, since the end of file will not have been seen. If the input terminates because of end of file, then eof()
will have been set; if no other characters have been input, then std::failbit
will also have been set. So the condition eof() && !fail()
means that you've read the last line, and that it was missing the '\n'
.
Upvotes: 3