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

📄 proj12_17.cpp

📁 C++程序设计教程的全部源代码 包含与教程同步的PPT 方便学习
💻 CPP
字号:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{  
	int j;
	fstream file("hello.txt",ios::in|ios::out|ios::app|ios::binary);
	if(!file)
	{ 
		cerr << "文件打开失败"<<endl;
		exit(-1);
	}
	for (int i = 0; i < 20 ; i++)
	{
		j = i * 2;
		//数据写入
		file.write((char *)&j,sizeof(int));
	}
	file.close();
	file.open("hello.txt" , ios::in|ios::binary);
	while(file.read((char *)&i , sizeof(int)))
		cout << i << ' ';
	file.clear();
	file.seekg(0);
	file.seekg(48);
	file.read((char *)&i,sizeof(int));
	cout << endl << "第13个数是" << i <<endl;
	file.close();
}

⌨️ 快捷键说明

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