我是靠谱客的博主 繁荣火龙果,这篇文章主要介绍C++使用文件流写二进制文件,现在分享给大家,希望可以做个参考。

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

int main()
{
	string name;
	int age;
	ofstream outfile;
	outfile.open("user1.txt",ios::out | ios::trunc | ios::binary);

	while (1)
	{
		cout << "请用户输入姓名" << endl;
		cin >> name;
		if (cin.eof())
		{
			break;
		}
		outfile << name << endl;

		cout << "请用户输入年龄" << endl;
		cin >> age;
		outfile.write((char*)&age, sizeof(age));

	}

	outfile.close();
	system("pause");
	return 0;
}

最后

以上就是繁荣火龙果最近收集整理的关于C++使用文件流写二进制文件的全部内容,更多相关C++使用文件流写二进制文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(122)

评论列表共有 0 条评论

立即
投稿
返回
顶部