5.二进制文件读写.docx

1.二进制写入,ios::binary #includeiostream #include fstream #include string using namespace std; struct MyStruct { char *p = 北京是帝都; int num = 20; double db = 10.98; char ch = a; }; void main1() { ofstream fout(E:\\wen.txt, ios::out); ifstream fin(E:\\wen.txt); //下面的大小时24 std::cout sizeof(MyStruct) std::endl; MyStruct my1; //向文件中写入内容 fout my1.p my1.num my1.db my1.ch \n; fout.close(); char str[100] = { 0 }; //提取文件内容 fin.getline(str, 100, 0); std::cout str std::endl; fin.close(); cin.get(); //运行结果是: //24 //北京是帝都 20 10.98 a //同时在E盘生成了wen.txt } void main() { MyStr

文档评论(0)

1亿VIP精品文档

相关文档