Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 12-28-2004, 09:11 PM   #11
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: C++ Beginner

i don't understand what you mean by system intensive... system ("pause"); is much more efficent than cin.get();

using cin.get(); the user has to press enter, he's likely to press serveral buttons before hitting enter.

system ("pause"); informs you Press any key to continue... after a key is pressed it resumes...

and i'm curious to know who would be so troubled by it that they would call it "highly unrecommended"

only thing going for cin.get(); is it's more portable, system ("pause"); doesn't work all platforms. and there's pleanty of ways cin.get(); could fail. if you haven't cleared the input buffer before you use it, your program would just flick by anyway.
__________________

__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Old 12-28-2004, 09:24 PM   #12
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: C++ Beginner

#include <iostream>
#include <limits>

void pause()
{
using namespace std;

try
{
// First clear the stream state flags
cin.clear();
}
catch (ios_base::failure const& x)
{
// Ignore any ios state exceptions
}

// Then clear anything that was in the buffer
cin.ignore(numeric_limits<streamsize>::max());

// Then get a char
cin.get();
}

// Note that this function *still* doesn't print out any
// "press enter" message

That is what's required to emulate system ("pause"); with cin.get(); and that doesn't even do any cleanup afterwards.
__________________

__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 03:01 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0