Hello,
Several Weeks ago I asked a question about testing for the end of an input file.
I have been using this method pretty well for inputting information from an external file. I am using C++.
-
char line[50];
-
while(file>>line){
Where line is a c-string and file is an input stream. But this only reads until the first space it encounters. I now want to try to take in an entire line, regardless of what it contains (such as whitespace) as a string and then parse the string later as appropriate.
When I try
- string line;
-
while(getline(file, line)){
Is working fine until my input file ( .txt) has 2 or more white lines at the end or if I have a white line in the middle of the file.
If there is 0 or 1 white line at the end, I have no problems; however when I have 2 or more empty lines I run into trouble and my program crashes.
Could you please explain what is going wrong? What am I missing?
Thanks You