for starters im just learning C++ so forgive my ignorance...
that being said... i need to pull 3 bits of info out of a text file.

  • Last name (name) - stored as a string
  • First initial (initial) - stored as a single character
  • Account balance (account) - stored as an int

    EG of text file:

         Alexander G 3031
         Webb O 6791
         Mueller U 1971
         Stokes A 2794
         Berger U 5766
         Garrison A 1074
         Franco E 2367
         Peters J 4828
         Stokes Q 8398
         Harrell O 2832

this is the code i have is....

  ifstream myfile ("small_names.txt");

  if (myfile.is_open())
    while (! myfile.eof() )

// this gets me through the file line by line but i have no idea how to pull the data out word by word....

      String lastN ;
      char firstN ;
      int amount ;

// b is a binary tree i have storing a customer class

      b.insert(lastN, firstN, amount);

else cout << "Unable to open file" << endl; 

thanks for any help.

Edited by Reverend Jim: Fixed formatting

7 Years
Discussion Span
Last Post by Beasts

The ifstream operator takes care of anything considering variable types.

myfile >> lastN >> firstN >> amount;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.