Oh my god, this is obviously a thread for new coders trying to learn - PLEASE don't get them in the habit of using System("anything"). It's fine for HW assignments or meaningless little programs (like Hello World) but if you get them in the habit of using it, then they'll use it in their finished projects in the future. It's slow and it's a security risk, among other things it also tags you as a complete beginner. So to summarize, DONT USE SYSTEM("anything")!!
I've put together an upgrade to Hello World that contains a good alternative to using system("pause") as well as posting a version where every line is commented because I know this is generally for beginners and another code snippet with no comments so the more advanced users still using system("pause") can read it more legibly. One more thing I would like to add is that yes, there are a lot of alternatives to system("pause") but remember that a lot more methods than system("pause") have some kind of flaw in them.
Code:
//HelloUser
//Include necessary preprocessors
#include <iostream> //Used for input/output (cin/cout)
#include <string> //Used for string
#include <limits> //Used for the numeric_limits
//This prevents us from having to do "std::" before everything
using namespace std;
//Start of function
int main ()
{
//String declaration for our input
string str;
//Outputs on the screen, "What is your name?"
cout << "What is your name? ";
//Here we take your answer to the question and convert it to our string declaration
cin >> str;
//Outputs Hello%s, my name is Hello%s (with %s being input stream) then skips/ends line
cout << "Hello " << str << ", my name is Hello" << str << endl;
//Alternative to system("pause") which should NEVER BE USED!!
//This will ensure that the original ENTER was pushed after the final <<
cin.ignore( numeric_limits<streamsize>::max(), 'n' );
//Outputs on screen you can quit by pressing ENTER
cout << "Press ENTER to quit!";
//Alternative to system("pause") which should NEVER BE USED!!
cin.ignore(numeric_limits<streamsize>::max(), 'n' );
//Outputs the text below
cout << "Bye, make sure you program me even better next time!!";
//Return function telling our program that it exited with no errors
return 0;
}
Code:
//HelloUser
#include <iostream>
#include <string>
#include <limits>
using namespace std;
int main ()
{
string str;
cout << "What is your name? ";
cin >> str;
cout << "Hello " << str << ", my name is Hello" << str << endl;
cin.ignore( numeric_limits<streamsize>::max(), 'n' );
cout << "Press ENTER to quit!";
cin.ignore(numeric_limits<streamsize>::max(), 'n' );
cout << "Bye, make sure you program me even better next time!!";
return 0;
}
PS: I also just noticed that you had said for C++ to use cin.get() twice. That's, again, a completely improper way of going about it and doesn't even make sense. Your making the user have to press enter TWICE while giving him absolutely no notification of what he's supposed to do. Please learn to do it the right way now before you get in a bad habit of that.