I am pretty new to C++ programming. My objective is to copy the content of one file into another file.
My code like below:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<fstream.h>
int main(){
    ifstream file1;
    ofstream file2;
    char ch;
    char sfile[10], tfile[10];
    cout<<"\nEnter the source filename: ";
    cin>>sfile;
    cout<<"\nEnter the target filename: ";
    cin>>tfile;
    file2.open(sfile);
    file2<<"hello world";
    file2.close();
    file1.open(sfile);
    file2.open(tfile);
    while(!file1.eof()){
        file1.get(ch);
        cout<<ch;
        if(file1.get(ch) == " "){
            continue;
        }
    file2<<ch;
    }
    file1.close();
    file2.close();
    return 0;
}
However I am not getting the correct result in the output file. It should have been helloworld but I am getting el olÿ in the output file.
Not sure what wrong am I doing here. Can anyone please help me in this?
 
     
     
    