seeking.cpp
来自「This is the second part of that lab manu」· C++ 代码 · 共 26 行
CPP
26 行
//: C05:Seeking.cpp
// From "Thinking in C++, 2nd Edition, Volume 2"
// by Bruce Eckel & Chuck Allison, (c) 2001 MindView, Inc.
// Available at www.BruceEckel.com.
// Seeking in iostreams
//{L} ../TestSuite/Test
#include "../require.h"
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream in("Seeking.cpp");
assure(in, "Seeking.cpp"); // File must already exist
in.seekg(0, ios::end); // End of file
streampos sp = in.tellg(); // Size of file
cout << "file size = " << sp << endl;
in.seekg(-sp/10, ios::end);
streampos sp2 = in.tellg();
in.seekg(0, ios::beg); // Start of file
cout << in.rdbuf(); // Print whole file
in.seekg(sp2); // Move to streampos
// Prints the last 1/10th of the file:
cout << endl << endl << in.rdbuf() << endl;
} ///:~
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?