error in while loop
Mar 5, 2012 at 2:17am UTC
"invalid operands of types 'char' and unresolved overloaded function type>' to binary 'operator<<'" <-- what does this error mean? It is the only error I am getting on my program and I can't figure out how to get it to run properly. Here is my program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#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;
}
Mar 5, 2012 at 2:59am UTC
Not sure if this is what you want
but what it does is.
Say you have ...
records.txt
0123456789
This code will change it to
corrected.txt
9876543210
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <string>
#include <fstream>
using namespace std;
int main ()
{
ifstream inFile;
inFile.open("records.txt" );
ofstream outFile;
outFile.open("corrected.txt" );
while (!inFile.eof())
{
string num="" , temp="" ;
inFile >> num;
temp =num;
int j = num.length()-1;
int length = num.length();
for (int i = 0; i <length ;i++)
{
temp[i] = num[j];
outFile<<temp[i];
j--;
}
outFile<<endl;
}
inFile.close();
outFile.close();
return 0;
}
Last edited on Mar 5, 2012 at 3:54am UTC
Mar 5, 2012 at 4:07am UTC
thank you so much. I tried switching the program and creating some sort of array but that wasn't working either.
Mar 5, 2012 at 4:14am UTC
Strings are basicly character arrays.
Topic archived. No new replies allowed.