#include <iostream>
#include <string>
#include <cstdlib>
usingnamespace std;
int main ( ) {
int value;
char strValue [80], Result [80];
cout << "Enter a number: ";
cin >> value;
cout << "Enter a string: ";
cin >> strValue;
// Conversion of string to integer
if ( atoi (strValue) == value )
cout << "Very good they are the same" << endl;
// Conversion of integer to string
itoa ( value, Result, 10 );
cout << "--> " << Result << endl;
return 0;
}
Strings cannot be compared to numeric values without some kind of conversion. There are other ways of doing this, this is just one example
You will lose precision if you use atoi, so only use that if you are working with integers only. Generally, I try to stick with C++, like std::to_string. atoi actually comes from C.