[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] C++ programming: keeping count of data items read from file



"H.S." wrote:

> Michael Marsh wrote:

>>     Can you read full lines out into, eg, a stringstream, and parse your
>>     doubles out of that?  You'd hit an EOF at the end of each line in that
>>     case.  I'm not sure how you'd get stream out line-at-a-time, though
>>     there may be a stream operator that sets the appropriate behavior.
> 
> Yup, that could be done by getting a line till the end of "\n" character and then parsing the line. I was just wondering if there was any other way (was trying to avoid parsing).

std::getline() ?  I think there is a version that outputs the result as
a string, from which you can then create an istringstream.

You can read numbers from an istringstream the same way as from cin with
">>" operators, so the amount of parsing should be minimal (as long as
the file is not corrupt).

best regards,

-- 
Kevin B. McCarty <kmccarty@gmail.com>
WWW: http://www.starplot.org/
WWW: http://people.debian.org/~kmccarty/
GPG: public key ID 4F83C751


Reply to: