📄 main.cpp
字号:
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
void WriteFile() {
ofstream MyFile("/seek.dat");
// First batch
MyFile.put(5);
MyFile.write("abcde", 5);
// Second batch
MyFile.put(8);
MyFile.write("qwertyui", 8);
MyFile.close();
}
void ReadFile() {
ifstream MyFile("/seek.dat");
// Read first byte and skip past
// the first batch.
int x = (int)(MyFile.get());
MyFile.seekg(x, ios_base::cur);
// Read the second batch
x = (int)(MyFile.get());
char *ptr = new char[x + 1];
ptr[x] = '\0';
MyFile.read(ptr, x);
cout << ptr << endl;
// Return to previous batch
MyFile.seekg(0, ios_base::beg);
x = (int)(MyFile.get());
ptr = new char[x + 1];
ptr[x] = '\0';
MyFile.read(ptr, x);
cout << ptr << endl;
// Try travling from the end, just for grins.
MyFile.seekg(-5, ios_base::end);
char ch = MyFile.get();
cout << ch << endl;
MyFile.close();
}
int main(int argc, char *argv[])
{
WriteFile();
ReadFile();
system("PAUSE");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -