Problem about append 2 files

Hi all.
I have 2 files:
exam1.txt: cplusplus
exam2.txt: is a general-purpose programming language
I want to convert exam1.txt to uppercase, then append exam2.txt to exam1.txt, result:
CPLUSPLUS is a general-purpose programming language

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <fstream>

int main()
{
    std::fstream f1;
    std::fstream f2;
    char c;
    f1.open("exam1.txt");
    while (f1>>c)
    {
        f1.seekg(-1,std::ios::cur);
        f1<<char(toupper(c));
    }
    f1<<' ';
    f2.open("exam2.txt");
    while (f2.get(c))
        f1<<c;
    f1.close();
    f2.close();
}

Convert to uppercase is ok, but append exam2 to exam1 is'nt.
Please help me, thank you very much.
Last edited on
The problem is that after the first loop f1 is in an error state. To reset the error state use clear(). See:

http://www.cplusplus.com/reference/ios/ios/clear/

So put f1.clear(); after the loop before line 15.

Thanks coder777. Have a nice day.
Topic archived. No new replies allowed.