Your code rises many questions.
- Why do you want to limit the output to six characters (while, you know,
int
can be much more bigger)? - Why are you trying to represent a uninitialized value (
x
)? - Why are you first representing the
int
value with a wide string and then converting it to ANSI one?
Richard code, addressing very carefully point 3, shows the way to go. However,
if you remove the six characters constraint, you could also use the following approach:
#include<iostream>
#include <sstream>
using namespace std;
int main()
{
int i = 12345;
string s;
ostringstream iss;
iss << i;
s = iss.str();
cout << "the string representation of the number is " << s << endl;
}