我试图理解这段使 operator 过载的代码>>
。我想我不明白的是为什么不拥有
is.open(fileName);
而不是is.open(fileName.data());
. 或者fileName.data()
.
ifstream& operator>> (ifstream& is, TheMatrix& myMatrix)
{
string fileName;
cout << "Enter a file name -> ";
cin >> fileName;
is.open(fileName.data());
for (int i=0; i< 5; i++)
for (int j=0; j<5; j++)
is >> myMatrix.M[i][j];
return is;
}
谢谢