⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 C++STL课本中的源程序代码己经验证过了可以通过编译和运行。
💻 CPP
字号:
#include <fstream>
#include <iostream>
using namespace std; 

struct Student{
	char name[8];
	int year;
};

int main(void){
	Student st;
	strcpy(st.name, "宋公明"); 
	st.year=18;
	//
	ofstream wFileStream;
	wFileStream.open("d:\\student.txt", ios::out|ios::binary);
	if(!wFileStream){
		cout << "打开文件失败" << endl;
		return 1;
	}
	wFileStream.write(reinterpret_cast<char*>(&st), sizeof(Student));
	wFileStream.close();
	//
	ifstream rFileStream;
	rFileStream.open("d:\\student.txt", ios::in|ios::binary);
	rFileStream.read(reinterpret_cast<char*>(&st), sizeof(Student));
	cout << st.name << "  " << st.year << endl;
	rFileStream.close();
	return 0;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -