使用operator >>指向ifstream对象的指针

apt*_*t45 1 c++ pointers operators ifstream

为什么在以下代码中指令os->operator>> input错误?不是operator >>对象*os的返回值?

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
  double input;
  ifstream * os = new ifstream("prova.dat");
  os->operator>> input;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

mas*_*oud 5

当您想要>>用作方法时,您需要()像普通函数一样传递参数.要取消引用它,您应该使用以下两种方式:

os->operator >> (input);
Run Code Online (Sandbox Code Playgroud)

要么

*os >> input;
Run Code Online (Sandbox Code Playgroud)

注意:为什么指针,何时可以使用自动对象或引用.此外,您需要管理已分配的对象并释放它.