Sign in to follow this  

Opening data

This topic is 4308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You read it back the same way, a file stream is just like a keyboard stream.

string var;
myfile << "blah";
myfile >> var;
cout << var; //outputs blah (if myfile is a fstream object)

google search

Share this post


Link to post
Share on other sites
Depends on what kind of info and how you want to get it. Shortly put, you associate an ifstream object with a file and then it's the reverse of ofstream: myfile >> blah.
here is a tutorial.
A snippet from the tutorial:
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}

else cout << "Unable to open file";

return 0;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thank you. Im going to try it in a minute. Thanks again.

Share this post


Link to post
Share on other sites

This topic is 4308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this