Hi, I have written a program for reversing a digit but I get "error C2664: 'strcpy' : cannot convert parameter 2 from 'std::string' to 'const char *'
Which I don't get since strcpy is supposed to change a string to a char array.
Any clues for whats going on here?
#include <iostream>
#include <iomanip>
#include <string>
#include <numeric>
#include <sstream>
using namespace std;
string itoa(long n);
int reverseDigit(int x);
int main ()
{
int number;
cout << "Enter number to be reversed: " << endl;
cin >> number;
cout << endl;
cout << "Reversed number is: " << reverseDigit(number) << endl;
system ("pause");
return 0;
}
int reverseDigit(int x)
{
/*char reverse[100];*/
char reverse2[100];
string reverse1;
string reverse3;
int revdig;
reverse1 = itoa(x);
/*reverse1.assign(reverse);*/
unsigned int i;
for (i = reverse1.size() ; i = 0; i--)
{
reverse3.push_back(reverse1[i]);
}
strcpy(reverse2, reverse3);
revdig = atoi(reverse2);
return revdig;
}
string itoa(long n)
{
stringstream stream;
stream << n;
return stream.str();
}