-1

怎么办?当你试图回答这个问题时,试着更具体一点。没有额外的细节。我收到一个错误

no match for operator<< in theFileIn<<number
#include<iostream>
#include<fstream>

using namespace std;

int main()
{
int number;
string name;

ofstream theFileOut;
ifstream theFileIn;

theFileOut.open("Sansa.txt");
cout << "Enter the number and the name"<<endl;

while(cin>> number>> name)
{
    theFileOut<<number<<" "<<name<<endl;
}

theFileOut.close();
theFileIn.open("sansa.txt");

while(theFileIn>>number>>name)
{
    theFileIn << number<<" "<<name<<endl;
}

return 0;
}
4

2 回答 2

2

问题在这里:

  theFileIn << number<<" "<<name<<endl;

theFileInifstream对象,不能<<与 ifstream 对象一起使用。你可能的意思是:

 cout << number<<" "<<name<<endl;
于 2013-06-25T15:49:05.603 回答
1

这是错误的:

theFileIn<<number<<" "<<name<<endl;

您需要切换theFileOut其他内容,最好使用cout.

于 2013-06-25T15:50:39.803 回答