Can anyone help me figure out how to create a cin statement that does not halt a program from placing output on the screen?
Can anyone help me figure out how to create a cin statement that does not halt a program from placing output on the screen?
I dont quite get the question you are asking, could you elaborate a little?
Try looking into cin.peek( ).
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
>Can anyone help me figure out how to create a cin statement that does not halt a program from placing output on the screen?
cin cannot do this. What you want is a second process/thread of execution. Or you could perform some kind of non-blocking test and read to get some of that functionality:
But that isn't nearly as powerful as a second process, and can get cumbersome.Code:#include <iostream> #include <string> // Nonstandard #include <windows.h> // For sleep #include <conio.h> // For kbhit void next_bar() { static size_t pos; static std::string spin ( "|\\-/" ); std::cout<< spin[pos++ % spin.length()]; std::cout<<'\b'<<std::flush; Sleep ( 100 ); // Slow the bar down a bit } int main() { std::string name; bool done = false; std::cout<<"Enter your name: "<<std::flush; while ( !done ) { if ( kbhit() ) { std::getline ( std::cin, name ); done = true; } else next_bar(); } std::cout<<"Hello, "<< name <<'!'<<std::endl; }
-Prelude
My best code is written with the delete key.
Forgot to return 0.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
I presume you're referencing Prelude's code? If so, return 0 is not required for a return from main() in C++, as it is the guaranteed default.Originally posted by XSquared
Forgot to return 0.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
>I presume you're referencing Prelude's code?
Indeed.
>If so, return 0 is not required for a return from main() in C++, as it is the guaranteed default.
I didn't know that. VC++ always spits out an error whenever I forget to.
[edit]
I guess I was wrong. Checked Stroustrup's site and it does mention that. Cool
[/edit]
Last edited by XSquared; 03-17-2003 at 03:59 PM.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie