Reputation: 31
I'm getting the following error:
invalid operands of types 'char' and unresolved overloaded function type>' to binary 'operator<<'
What does it mean?
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
inFile.open("records.txt");
ofstream outFile;
outFile.open("corrected.txt");
while (inFile.good())
{
string num, temp;
inFile >> num;
outFile << temp.at(0)=num.at(9) << temp.at(1)=num.at(8)
<< temp.at(2)=num.at(7) << temp.at(3)=num.at(6)
<< temp.at(4)=num.at(5) << temp.at(5)=num.at(4)
<< temp.at(6)=num.at(3) << temp.at(7)=num.at(2)
<< temp.at(8)=num.at(1) << temp.at(9)=num.at(0) << endl;
// invalid operands of types 'char' and unresolved overloaded function type>'
// to binary 'operator<<'
}
return 0;
}
This program is supposed to reverse back a list of phone numbers that have been reversed.
Upvotes: 2
Views: 11088
Reputation: 182753
You need to parenthesize your expressions or the wrong precedence breaks the code.
Replace temp.at(0)=num.at(9)
with (temp.at(0)=num.at(9))
, and so on. Then it will compile.
outFile << (temp.at(0)=num.at(9)) << (temp.at(1)=num.at(8))
<< (temp.at(2)=num.at(7)) << (temp.at(3)=num.at(6))
<< (temp.at(4)=num.at(5)) << (temp.at(5)=num.at(4))
<< (temp.at(6)=num.at(3)) << (temp.at(7)=num.at(2))
<< (temp.at(8)=num.at(1)) << (temp.at(9)=num.at(0)) << endl;
Upvotes: 5