I wrote this code for a homework problem. The instructions say that there is a list of phone numbers that were reversed (ex. 6463124137, needs to be 7314213646) and the program needs to reverse them back. My professor also included this hint: "Hint: One way to reverse the number would be to accept all the input as strings, create a temporary string of length 10, and then manually change each character of the string (e.g. temp.at(2)=number.at(8); etc.)" I tried doing that but the program isn't working. It is not outputting, and there are a few errors. If anyone could explain to me what I am doing wrong I would really appreciate it.
#include <string>
#include <fstream>
using namespace std;
int main ()
{
ifstream inFile;
inFile.open("records.txt");
ofstream outFile;
outFile.open("corrected.txt");
string num, temp;
while (inFile.good())
{
string temp.length(10) //error: expected initializer before '.' token
inFile >> num >> endl;
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; //error: invalid operands of types 'char' and
//unresolved overloaded function type>' to binary 'operator<<'
}
return 0;
}