1

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;
}
icedwater
  • 4,701
  • 3
  • 35
  • 50
bc8787
  • 41
  • 1
  • 6

1 Answers1

3

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?

Community
  • 1
  • 1
DaoWen
  • 32,589
  • 6
  • 74
  • 101
  • 1
    [The STL is obsolete; you're using the C++ Standard Library](http://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all-about/5205571#5205571) – paddy Jul 08 '13 at 02:01
  • @paddy - Thanks for the clarification. I had no idea there were people that opposed calling the parts of the standard library that came from STL as STL, nor did I realize so many people think that STL is the _entire_ C++ standard library. – DaoWen Jul 08 '13 at 02:07