File to file data transfer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <fstream>
#include <iostream>
using namespace std;
int main()
{fstream file,file1;
long size,first,end;
file.open("C:\\Example.txt",ios::in|ios::binary);
file1.open("D:\\Example2.txt",ios::out|ios::binary);
first=file.tellg();
file.seekg(0,ios::end);
end=file.tellg();
size=end-first;
char a[size];
for(int i=0;i<size;i++){
file>>a[i];
file1<<a[i];
}
  system("PAUSE");
    return EXIT_SUCCESS;
}

My input datas in Example.txt file:abcd1
Output datas in Example2.txt file:Ë´€|$
closed account (DSLq5Di1)
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
27
28
29
30
31
32
33
34
35
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    fstream file,file1;
    long size,first,end;

    file.open("C:\\Example.txt",ios::in|ios::binary);
    file1.open("D:\\Example2.txt",ios::out|ios::binary);

    first=file.tellg();
    file.seekg(0,ios::end); // seek back to the beginning of your file before
                            // trying to extract any characters.
    end=file.tellg();
    size=end-first;

    char a[size]; // non-constant size expression, does that even compile?
    string line;

    for(int i=0;i<size;i++)
    while (!file.eof())
    {
        file>>a[i];
        file1<<a[i];
        getline(file, line);
        file1 << line;
    }

    system("PAUSE");
    return EXIT_SUCCESS;
}

Looks a tad more readable dont you think..? The lines in bold are where you had errors, my additions are in italics, and everything unnecessary I've put a line through.
Thank u sloppy9.This is working.
Last edited on
long int begin,end,length;

begin=file.tellg();
file.seekg(0,ios::end);
end=file.tellg();
length=end-begin;

textBox1->Text=length.ToString();

My input datas in file : onur
Normally 4 produce But Output data in textBox : 17558 or 58738 .. similar number
why??
Topic archived. No new replies allowed.