I have been substituting all I can with cin.getline instead of cin, since apparently that leaves behind a \n in the stream. but what if I want the user to just input one character that isn't an array/string? Some would maybe say that I could just set the char variable to be a one dimensional array, and the user would only know to enter one character. But I thought that would be unprofessional seeming, and it would also make it where I couldn't use == and would have to use that string compare function. So, is there some way I could get around this without using cin?
Trying to handle all sorts of possible user input on console is very difficult and error-prone. You never know what kind of input user entered in. This is why a lot of companies have made GUI for user input. Using the GUI mode, you can filter what user can enter and this can save a lot of head-aches on your end.
With browser, GUI development is very easy (assume simple HTML and some CSS, JavaScript) thrown in.
Without browser, do consider the different GUI SDK around.
Edit:
Oops I forget to mention ncurses someone told me. Basically you use the console in a "GUI-like" manner and this can control user input only valid characters. Worth a look but in comparison to "true-bred" GUI, I feel the ncurses UI still lack that *oomph* :P
But his stated concern is the leftover newline in the stream. std::cin.get(char) still leaves newlines in the stream (unless, of course, it is the newline character being extracted).
Rather than force your code to fit an artificial rule, you should rather apply an actual rule:
The user will always press ENTER to after every input.
Hence, whether the user is inputting his name or a number, he will press ENTER to signal he is done. That means that your program needs to extract that enter key press after every user input.
Hence:
1 2 3 4 5 6 7 8 9 10
string user_name;
unsigned user_age;
cout << "Please enter your full name: ";
getline( cin, user_name );
cout << "Please enter your age: ";
cin >> user_age;
cin.clear();
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );