F
Fred H
Hi
I'm trying to write a more or less fool proof
method of getting lines of text from either
standard input (cin) or files (ifstream). It
needs to be fool proof for later use, since
I can be quite the fool ;-)
For both cin and ifsteram the method getline
is defined, and I kind of like it, since I can
specify a maximum number of characters to get.
But getline requires a pointer to a char array,
and I would really like to put the input into
a string. I know that I can make myself a char
array, and use that as a temporary buffer, and
then insert it into my string when I'm done, but
that would be too simple, and the FAQ tells me
that arrays are evil, and I agree
I was thinking that maybe something along the
lines of
string buf;
buf.reserver(LENGTH);
cin.getline(buf.fake_cstring_pointer,LENGTH)
would work, but this way of using a string is
kind of messy, so I figured there would be a
version of getline that could actually take a
reference to a string, and ask it for it's
capacity on its own, and use that as the max
characters to get, or something like that.
My point is: I haven't been able to find any
such getlinish function. So... HELP!
Cheers
-Fred
I'm trying to write a more or less fool proof
method of getting lines of text from either
standard input (cin) or files (ifstream). It
needs to be fool proof for later use, since
I can be quite the fool ;-)
For both cin and ifsteram the method getline
is defined, and I kind of like it, since I can
specify a maximum number of characters to get.
But getline requires a pointer to a char array,
and I would really like to put the input into
a string. I know that I can make myself a char
array, and use that as a temporary buffer, and
then insert it into my string when I'm done, but
that would be too simple, and the FAQ tells me
that arrays are evil, and I agree
I was thinking that maybe something along the
lines of
string buf;
buf.reserver(LENGTH);
cin.getline(buf.fake_cstring_pointer,LENGTH)
would work, but this way of using a string is
kind of messy, so I figured there would be a
version of getline that could actually take a
reference to a string, and ask it for it's
capacity on its own, and use that as the max
characters to get, or something like that.
My point is: I haven't been able to find any
such getlinish function. So... HELP!
Cheers
-Fred