为什么在下面的代码中指令os->operator>> input
错误?不是操作符的返回值>>对象* os?使用操作符>>带指向ifstream对象的指针
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
double input;
ifstream * os = new ifstream("prova.dat");
os->operator>> input;
return 0;
}
不要使用指向'ifstream's的指针!他们不打算这样使用。必要时可以通过参考传递。 – Rook
@请问具体原因是什么? –
@RoyIacob与任何其他对象一样,不应通过原始指针引用来使用,只要可以避免。 –