Just a note, if you don't want to use cin.ignore, you can use:
cpp
char InputChar () {
char returnVal;'
returnVal=cin.get();
while (cin.get()!='\n');
return (returnVal);
}
/*To be used like:
char character;
character=InputChar();
*/
Of course, I would always look into using the string library:
cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string input;
getline(cin, input); //easiest input for strings
cout << input << endl << "Press any key then enter to exit. ";
cin >> input;
return 0;
}
String library makes our lives much simpler. Now, to make it so that our input isn't a cin, but a cin.get(),
cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string input;
getline(cin, input); //easiest input for strings
cout << input << endl << "Press any key to exit. ";
cin.get();
return 0;
}
For future reference: The getline function in the string library when used that way will clear the input buffer for you, so you can just use getline and a dummy string instead of cin.ignore, just to say.
This post has been edited by polymath: 8 Jul, 2008 - 05:15 PM