P
Peter Olcott
Does C++ have anything like this?
Like what?Peter said:Does C++ have anything like this?
Does C++ have anything that uses something like a
std::string for text file input?
Peter Olcott wrote:
Please don't top-post.
std::string s;
std::cin >> s;
osmium said:"Ian Collins" write:
Based on the OPs question, I suspect he wants to change cin to the name of a
file opened for reading.
osmium said:Based on the OPs question, I suspect he wants to change cin to the name of a
file opened for reading.
Peter Olcott said:Does C++ have anything like this?
Jim Langston said:file input using std::string.
It depends on what you mean, like others have said. Do
you want to input to a std::string, or read from a
std::string?
Input to a std::string: (untested code)
#include <istream>
#include <string>
int main()
{
std::ifstream Input("Myfile.ext");
std::string Data;
if ( std::getline( Input, Data ) )
news:[email protected]...
Yes this is what I was talking about, I need text delimited
by lines.
What is the "if" for ???
news:[email protected]...
Yes this is what I was talking about, I need text
delimited
by lines.
What is the "if" for ???
James Kanze said:On Jul 26, 3:58 am, "Peter Olcott" <[email protected]>
wrote:[...]news:[email protected]...To test whether the input succeeded or not. std::getlineif ( std::getline( Input, Data ) )
Yes this is what I was talking about, I need text
delimited
by lines.
What is the "if" for ???
(like the << operators) returns a reference to the stream it
read; when used in a condition, the stream will act true if
there has been no error to date, and false if there was some
sort of error (typically, in this case, due to trying to
read beyond the end of file).
So it would typically be written like this?
while ( std::getline( Input, Data ) )
;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.