Thread: Moving on
View Single Post
Old
legolizard
Senior Member
 
legolizard's Avatar
 
Status: Offline
Posts: 242
Join Date: Jan 2011
Location: Aboard the Hyperion escaping the zerg.
Default 08-07-2011, 10:06 PM

Very good state of mind. cin.get(); also comes from the standard namspace within the iostream header file. It is derived from the normal cin>>.

What it does is wait for the user to enter something it then treats it as a char meaining you could type "Blalalalaalalalalala" and then cin.get() would only recieve 'B' where as cin>> whould take the entire string. When you press enter cin.get() takes in whatever you typed in executes and then the main() goes to to the last line return 0; thereby terminating the program. cin.get() can also be used for user input because of this and is not just for pausing. You could use it like this for example:

Code:
#include <iostream>

using namespace std;

int main()
{
    char myChar;
    
    cin.get(myChar);
    
    cout<<myChar<<endl;
    
    system("PAUSE");//I used system("PAUSE"); to make it less confusing.
    
return 0; 

}


"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein
   
Reply With Quote