Beginner Visual Studio easy Question

I just started learning C++, i have an intermediate background with Java. Following Tony Gaddis book starting out with c++ i was doing my first program in Visual Studio since i am still a student i got the software for free. and the first example in the book goes like this:
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
cout << "programming is fun"
return 0;
}


but when i try to run it the console exits giving me this in the output (The program '[2468] HelloWorld.exe' has exited with code 0 (0x0).) After looking at a youtube video i was wondering why i have to add cin.get(); for the console to stay open?

also the recommended software for this was MinGW but didn't feel like installing it since i already had the visual studio.
I have visual studio as well and if you press CTRL+F5 the prompt should stay open after running.
Last edited on
Because, your program code has no instruction to wait. Its instruction is to print "programming is fun" and then exit with code 0. If you add cin.get() it'll wait for the user to type in something and press ENTER. Therefore it doesn't close as it waits for input. Alternatively you can use system("pause"); but its not recommended.
Last edited on
Any other tips and tricks u can can recommend as i am making a transition from java to c++? ex: websites, text, etc...
Well both the languages are kinda similar so you'd have probably little to no problems.
well i was looking for something similar to codingbat but for c++ is there such a thing? with problems to solve.
Last edited on
Topic archived. No new replies allowed.