| | |
getline failing to read from data file?
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
n8makar - congratulations on finding your own solution. I'm surprised the others who responded didn't spot that.
Mixing input with the extraction operator ( >> ) and getlline is a frequent source of problems for beginning students, that left over newline causes no end of frustration.
Now consider what happens if data is like:
Your use of fin.ignore( ) will throw away the data we actually want.
An alternative means of removing the whitespace (blanks, tabs, newlines) is the
Mixing input with the extraction operator ( >> ) and getlline is a frequent source of problems for beginning students, that left over newline causes no end of frustration.
Now consider what happens if data is like:
C++ Syntax (Toggle Plain Text)
12345 This is the name of the thing 8765 Some other thing
An alternative means of removing the whitespace (blanks, tabs, newlines) is the
ws manipulator. You might use it like: C++ Syntax (Toggle Plain Text)
fin >> num_var; fin >> ws; //eats up whitspace till displayable char getline( fin, string_var );
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Connect 4 computer player
- Next Thread: Windows API - Use QT Now?
Views: 2456 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






