注册 登录
编程论坛 VC++/MFC

各位大侠看看这段代码对.wav文件的复制结果为什么不成功??

想学mfc 发布于 2012-07-11 15:54, 420 次点击
#include<iostream>
#include<fstream>

using namespace std;

void main()
{
    ifstream fin("D:\\123.wav",ios::binary);
    if(!fin)
    {
        cout<<"File open error!\n";
        return;
    }
    ofstream fout("D:\\bb\\123.wav",ios::binary);
    char c[1024];
    while(!fin.eof())
    {
        fin.read(c,1024);
        fout.write(c,fin.gcount());
    }
    fin.close();
    fout.close();
    cout<<"Copy over!\n";
}
1 回复
#2
hellovfp2012-07-12 12:32
#include<iostream>
#include<fstream>

using namespace std;

int main()
{
    ifstream fin("D:\\123.wav",ios::binary | ios::in);
    if(!fin)
    {
        cout<<"File open error!\n";
        return 1;
    }
    ofstream fout("D:\\bb\\123.wav",ios::binary | ios::out);
    if(!fout)
    {
        cout << "File create error!\n";
        return 2;
    }

    fout << fin.rdbuf();

    fin.close();
    fout.close();
    cout<<"Copy over!\n";
    return 0;
}
1