![]() |
| ||
| How to read end of line? I'm wanting the program to read a line out of file. I wish c++ had .eoln()! I get: test.cpp:10: no match for `std::ifstream& != char' operator obviously because I'm comparing the wrong data types. Quote:
Any help will be appreciated, Thanks Andy |
| ||
| Re: How to read end of line? If you're trying to read from a file, use some function that will read from a file. Sitting at the beginning of a file and waiting for the end to come will not do much. #include <iostream> |
| ||
| Re: How to read end of line? ^yeah but what if the line can't be treated as a string? On the line, I am wanting to get, there is going to be 1 to 5 double's. Since I don't know how many doubles are going to be on that line, I just need to grab the whole line. Then I was going to fill an array with how ever many double's were on that line: double arr[5]; int i; for (i=0; not end of the line; ++i) {infile>>arr[i]; } |
| ||
| Re: How to read end of line? I'd go with a vector of a vector of doubles. The vector of doubles per line, and the vector of these vectors for each line. |
| ||
| Re: How to read end of line? A sample. #include <iostream>There are probably better/easier ways to go about iterating through the loop, and I'm sure someone will let me know. |
| ||
| Re: How to read end of line? Okay, sorry, I'm still learning about all this stuff and I thought if you knew how many items were going to be used, then use an array? So you think I should do something like this... double num; vector<double> charges[0]; while (not end of the line) { file>>num; charges.push_back(num); } Am I on the right track, or am I way off? [EDIT] ...reading the code you posted... |
| ||
| Re: How to read end of line? Quote:
http://www.eskimo.com/~scs/C-faq/q12.2.html |
| ||
| Re: How to read end of line? Quote:
In my CS class, we haven't learned istringstream yet, so I don't know how I would have known how to do that. So all istringstream does is make each number on that one line ready to be stored into a variable? I appreciate your help. |
| ||
| Re: How to read end of line? Quote:
So the code I posted reads the whole line into a string, rather than going one value at a time (because both a newline and a space are whitespace characters, it might be tougher to distinguish using other means). Then it parses each double via the stringstream and >> operator. |
| All times are GMT -4. The time now is 8:45 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC