目录

tellg

描述 (Description)

它用于获取输入序列中的位置。

声明 (Declaration)

以下是std :: basic_istream :: tellg的声明。

pos_type tellg();

参数 (Parameters)

没有

返回值 (Return Value)

返回流中的当前位置。

异常 (Exceptions)

Basic guarantee - 如果抛出异常,则对象处于有效状态。

数据竞争 (Data races)

修改流对象。

例子 (Example)

在下面的示例中为std :: basic_istream :: tellg。

#include <iostream>     
#include <fstream>      
int main () {
   std::ifstream is ("test.txt", std::ifstream::binary);
   if (is) {
      is.seekg (0, is.end);
      int length = is.tellg();
      is.seekg (0, is.beg);
      char * buffer = new char [length];
      is.read (buffer,length);
      is.close();
      std::cout.write (buffer,length);
      delete[] buffer;
   }
   return 0;
}
↑回到顶部↑
WIKI教程 @2018