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);
}
myfile.close();
}

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

thanks for any help.

The ifstream operator takes care of anything considering variable types.

myfile >> lastN >> firstN >> amount;

That is really cool.
Thanks a ton.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.