September 9th, 2010, 12:51 AM
Console Cursor and cin
I'd like to make my project for c++ a little fancier than the rest. Instead of doing this:
cout << "Enter a: << endl;
cin >> a;
cout << "Enter b: << endl;
cin >> b;
cout << "Enter c: << endl;
cin >> c;
I'd like to output:
cout << "f(x) = ___x^2 + ____x + ____" << endl;
But then move the cursor back to the underscores and accept input there. I know I can set the cursor position with SetCursorPosition like this:
Cursor.X = 26;
Cursor.Y = 16;
however if I then try to:
cin >> a;
cin.clear(); // since I just input a number
cin.get(); //pause so I can observe where the cursor went.
The console application exits with a zero exit code (I returned 0 at the end of int main) and has no error codes. I thought adding a cin.clear() would resolve any extra \n's on the input stream, but the application is either crashing or cin.get() is finding a \n somewhere.
btw, this is Visual Studio 2010 (Visual C++) in a basic Win32 Console application.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.