Hi,
I would like to read an empty line. I would like an effect which is similar to:
But I would like to do it with cin stream. Is it possible?Code:cout << "Press enter to continue." getchar();
Best regards.
Hi,
I would like to read an empty line. I would like an effect which is similar to:
But I would like to do it with cin stream. Is it possible?Code:cout << "Press enter to continue." getchar();
Best regards.
cin.get();
Woop?
You could also put
I have heard this shunned some times though. I do this, but I am a noob. Just thought that might help. The effect you get from this isCode:system("PAUSE");
"Press any key to continue..."Make sure to put it on its own line though.
I only offer this because some compilers (like my own) does not use theI don't know why...Code:cin.get();
shadowsora15 : Really really really bad suggestion there. cin.get() is standard and system() can only be evil. Never ever use system().
Shadowsora15: that isnt possible. if you #include <iostream> cin.get() will be there. you just have to either "using namespace std;' or put "std::" before cin like so
std::cin.get();
it will be there though on any standard compiler.
system() is standard too, only the "pause" part is not.
However, I see nothing wrong with using system("pause") in some situations.
If you don't need portable code then it's a method that is simple and works as expected. You guys mentioned cin.get() but you didn't mention how if your stream is in a fail state cin.get() will fail or if there are leftover chars in the stream, the program will just continue on.
Another concern is security, but if someone has replaced pause on your system, then they could just have easily replaced your program. Besides, if someone is replacing programs on your system, it's already too late.
Finally, efficiency is the last criticism I hear, "you're spawning a new process to pause your current process", ok, but I ask, how efficiently do I need to pause my program? The tiny bit of resources used to pause my program is a small price to pay for the ease of use, especially for someone new to programming.
I would say there are no absolutes, do what's best for a given situation, which sometimes means using system() or gotos or macros or non-portable code
Last edited by Darryl; 05-31-2007 at 02:03 PM. Reason: spelling
There's an FAQ on this topic: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Not nessesarily. You could pass system() a NULL pointer. Though what good that would do unless you were intending to call system() later on I don't know.system() can only be evil.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.