c++中的文件输入/输出(6):一些有用的函数
原作:ilia yordanov, loobian@cpp-home.com
tellg() ——返回一个int型数值,它表示“内置指针”的当前位置。此函数仅当你在读取一个文件时有效。例如:
#include <fstream.h>
void main()
{
// 假如我们已经在test_file.txt中存有了“hello”的内容
ifstream file("test_file.txt");
char arr[10];
file.read(arr,10);
// 由于hello占5个字符,因此这里将返回5
cout << file.tellg() << endl;
file.close();
}