Em có hai đoạn code sau , em làm với mục đích sao chép tệp . Đoạn code 1 chạy ngon lành , sao y chang . Đoạn code 2 bị thiếu mất mấy chữ . Xin giải thích giùm em . Cảm ơn a .
Code 1:
Code:
void main() //sao tep vanban.txt qua tep vanban2.txt
{
clrscr();
char c[50];
int n;
fstream f("C:\\vanban.txt",ios::in|ios::binary);
fstream g("C:\\vanban2.txt",ios::out|ios::binary);
while(f.read(c,50),(n=f.gcount()))
g.write(c,n);
f.close();
g.close();
getch();
}
Code 2:
Code:
void main() //sao tep vanban.txt qua tep vanban2.txt
{
clrscr();
char c[50];
int n;
fstream f("C:\\vanban.txt",ios::in|ios::binary);
fstream g("C:\\vanban2.txt",ios::out|ios::binary);
while(f.read(c,50))
{
n=f.gcount();
g.write(c,n);
}
f.close();
g.close();
getch();
}