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.
 
#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.
 
Back
Top Bottom