Converting int to string. (or char)

I'm trying to make a program that will convert decimal to binary. I think I have the steps right but I need to put each character into a string or char array to output them in the right order. I thought I could do temp.ToString(), but that doesn't work. Also, how would I be able to check the input to make sure it is in fact an integer.

#include <iostream>
#include <string>

using namespace std;

int main()
{
int decimal = 0;
string output = "";
int temp;

cin >> decimal;

while(decimal > 0)
{
temp = decimal % 2;
output += temp;// <---
decimal /= 2;
}

cout << output << endl;
system("pause");
return 0;
}
output.push_back(temp+'0');

push_back is the method to add chars. +'0' is there to convert integers to ascii digit symbols.
Topic archived. No new replies allowed.