Quick question for experts....

Hello everyone, thanks for taking on this topic.

I have a read file ("exampleIn.txt") and i get the input from there
and after the program runs i print in a file ("examplOut.txt") .

I do not know how to show on the output file ("exampleOut.txt") the read input from the read file.

I hope i am making his clear enough.

Thanks for the advice
I think you should explain a bit better.
I understand that you have exampleIn.txt and examplOut.txt, you read from exampleIn.txt and write to examplOut.txt.
What problem are you having?
i need to print in the output file

The input from the read file exm:

j 123
e 345
e 543
j 675
.....

output file will show smthing like:

eTotal = 988
jTotal = 798

But i want the read input to show in the output file:

j 123
e 345
e 543
j 675
.....

*************
eTotal = 988
jTotal = 798


Does this help?
I do not know how to do that...
Thanks again
Last edited on
A possible solution:
* Read line by line the input file
* write the line to the output file
* put that line into a stringstream
* process that line
* repeat until you reach EOF on the input file
* print ********** and the totals on output file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int totale = 0, tempe = 0, totalj = 0, tempj = 0;
char type;

ifstream myOpenFile;
ofstream mySaveFile;
myOpenFile.open("exampleIn.txt");
mySaveFile.open("exampleOut.txt");

while(!myOpenFile.eof()){
    myOpenFile >> type;
    if(type = 'e'){
        myOpenFile >> tempe;
        totale += tempe;
        mySaveFile << type << " " << tempe << endl;
    }
    else{
        myOpenFile >> tempj;
        totalj += totalj;
        mySaveFile << type << " " << tempj << endl;
    }
}
mySaveFile << "***************" << endl;
mySaveFile << "Total e: " << totale << endl;
mySaveFile << "Total j: " << totalj << endl;
myOpenFile.close();
mySaveFile.close();
Last edited on
I am confused, a litle advise or example maybe.

I would apreciate it

Thanks everyone
Topic archived. No new replies allowed.