-
September 8th, 2010, 11:51 PM
#1
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;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Cursor);
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|