fstream 默认以字符方式读取和写文件,除非设置ios::binary

来源:互联网 发布:owncloud config.php 编辑:程序博客网 时间:2024/05/16 07:27
#include <fstream>#include <cstring>#include <iostream>using namespace std;void test(char name []){   ofstream fout;fout.open("2.jpg",ios::out|ios::binary);    ifstream fin;    fin.open("1.jpg",ios::in|ios::binary);    char content[4];    while(!fin.eof())        {fin.read(content,4);        cout<<fin.gcount()<<endl;            fout.write(content,fin.gcount());        }    //fout<<name;fout.write(name,strlen(name));    fout.close(); }int main (){    char name []="周zms12.457";    test(name);    return 0; } 
0 0
原创粉丝点击