#include <iostream>
using namespace std;
#include <string>
#include <fstream>
int main()
{
ofstream of;
of.open("e:\\123.txt");
of << 2000<< endl;
of << "helloworld" << endl;
of.put('Y'); //写操作中put()函数,只能向硬盘中输出一个,
int var = 12345;
of.write((const char*)&var, sizeof(int)); //char*并不是指的字符串,而是指的地址,在这边要强行转换(地址,长度)
of.close();
ifstream If;
If.open("e://123.txt");
//int va = 12345;
//If >> va; // >>读出整形
//cout << "硬盘到内存的数据为:" << va<<endl;
//char s[100] = {0};
//If >> s;
//cout << s << endl; // 读出字符串
//char ch;
//ch=If.get(); //这个读出来的是换行,没显示
//ch = If.get();
//cout << "读出的put字符是:" << ch << endl;
char s[100] = { 0 };
If.getline( s,sizeof(s));
cout << s << endl;
memset(s, 0, sizeof(s)); //memset(清除的数组,清楚为多少,数组的原来缓存区)函数,
If.getline(s, sizeof(s));
cout << s << endl;
memset(s, 0, sizeof(s));
int va = 1235;
If.read((char*) & va, sizeof(int));
cout << "通过二进制读出的数据为:" << va<<endl;
If.close();
return 0;
}