I have written all that I was told to by the tutorial's first lesson:http://www.cplusplus.com/doc/tutorial/, it is the lesson where you write "hello world", but unfortunately I do not know how to make that phrase appear on the screen. I said activate program because I do not know how to refer to this.
By the way: thanks in advance for all the help you give me.
I have just tried to compile, to click compile, and then run, when I do that a new window appear and close so quickly that I can not read anything in it.
There are a few ways to do this, though cin.get() is the most common from what I've seen. If your compiled code looks like this, then you're on the right track. The cin.get() function waits for the user to press a key, and then continues to the next line "return 0" which exits your program without errors.
int main()
{
// std::cin.get(); if you use cin >> 'something' anywhere.
std::cout << "press Enter to close" << std::endl;
std::cin.ignore(99, '\n');
return 0;
}
Edit;
You will find that if you use std::cin anywhere and don't have std::cin.get() to catch the user pressing 'enter'. Your exit method will get fuzzy.
I'm still new to C++ myself (coming from C#), and I find myself using std::cin.get() on everyline that uses cin >> somevariable. However with strings you can use: getline(cin, variable) but you need to: #include <string> for that.
Thank yo for the help, I did make the program run after copying your lines and pasting on my c++, however I do not understand why when I copy and paste from the tutorial I can not run the program. Why is that?
A lot of tutorials seem to neglect code to pause the program at the end. I had this issue when I was first learning C# years ago. however, if your using Visual Studio, you can do ctrl+F5 instead of F5. Then you can test your program without adding those lines.
An easy way to pause a program is to put system ("Pause") at end of code, but I wouldn't recommend it.
Another easy way is to put getch(); at end of code which does the same thing in a safer way. But you need to add #include<conio.h> at the beggining of code. Both will force you to push a button to continue, but getch(); is much safer.
mitaka12102: thanks, I was able to close the program with
getch();
mezmiro: "What program are you copying this C++ code into?"
Unfortunately I do not even know which compiler/IDE I am using. What they are for. Or how to change them. I just click "compile" on my c++ and then "run".