Wrote a program to convert a number to binary in C++ .I'm fairly new to C++ and I did this before and it wasn't done too well, but I feel like I made a few improvements. Please if there are any bad practices or something I might have done wrong, let me know. I know my naming isn't too well but i don't put much thought into that. Thanks.
#include <iostream>
#include <vector>
#include <string>
#include <iterator>
#include <fstream>
#include "modeset.h"
#include <locale>
#include <sstream>
using std::cout;
using std::cin;
using std::vector;
using std::string;
using std::endl;
using std::cerr;
using std::stringstream;
int convert_to_bin(int user_conv_num)
{
stringstream bin_in_string;
if(user_conv_num == 0)
{
return 0;
}
convert_to_bin(user_conv_num / 2);
bin_in_string<<user_conv_num % 2;
cout<<bin_in_string.str();
return 0;
}
int main()
{
long int user_conv_num = 0;
cout<<"(#)";
cin>>user_conv_num;
try
{
if(user_conv_num < 0) throw 1;
else
{
convert_to_bin(user_conv_num);
}
}
catch (int) {
cerr<<"Negative integer";
}
}