Hi,
just a quick question. if i have an input file with 6 lines of data. for example(ingnore the numbers 1 to 6, they indicate the file number and is not part of the file physically)

1. Peter 3 / + - *
2. Dahne 8 + - / *
3. Renee 7 - * + /
4. Charl 1 * / + -
5. Johan 2 / - * +
6. Sipho 4 * - / +

my question is, how do i go about firstly extracting data for example
string name= peter
int combo = 3
char op = / + - *

i am able to read the file line by line, but unable to stop at points to extract specific data.
my output file looks exactly like my input file.

the reason i need the extraction done to store to variable is because the numbers after the names go into a switch statement to perform a calculation, only the name, the operaters(/+-*) and answer is stored to the outfile.
how do i go about extracting?

#include <fstream>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cctype>
int main()
{
    using namespace std;
    ifstream in_stream;
    ofstream out_stream;
    in_stream.open("precedence.dat");
    if(in_stream.fail( ))
    {
        cout << "input file opening faild.\n";
        exit(1);
    }
    out_stream.open("results.dat");
    if (in_stream.fail( ))
    {
        cout << "output file opening failed.\n";
        exit(1);
    }
 string next;
    
    while(! in_stream.eof())
    {
          while(getline(in_stream,next))
        {
           out_stream<<next<<endl;
        }

  
    }
    in_stream.close( );
    out_stream.close( );
    return 0;



}
while (notFinishedReading)
{
  in_stream >> name;
  in_stream >> combo;
  in_stream >> op1;
  in_stream >> op2;
  in_stream >> op3;
  in_stream >> op4;

  // Do something with the data
}

or

while( in_stream >> name >> combo >> op1 >> op2 >> op3 >> op4)
{
   // do something with the data
}
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.