bc8787
bc8787

Reputation: 41

Storing data from a .dat file

I'm trying to store data from a .dat file. Using a while loop and ifstream I've managed to get it to print out exactly what I need, but I need to store what it's printing out so I can perform arithmetic operations on them. It seems like it's such a short leap from printing the info to storing the info, but I just can't figure it out.

Here's the code I've got so far:

int main()
{
    char name;
    cin.get(name);

    ifstream inStream;
    inStream.open("grade.dat");

    while (name != ' ')
    {
        inStream.get(name);
        cout << name;    
    }

    return 0;
}

Upvotes: 1

Views: 1044

Answers (1)

DaoWen
DaoWen

Reputation: 33019

You just need to put them all in some sort of data structure. I'd recommend one of the STL data structures since you're using C++. Fortunately for you, someone already asked how to read text from a file and store it in an STL vector!

Reading line from text file and putting the strings into a vector?

Upvotes: 3

Related Questions