Hi, I'm 17 and I just started using Sams Teach Yourself C++ 5th edition. Hilariously, I somehow managed to get stuck on the first lesson. I installed the MinGW, which came with the G++ compiler. I wrote a program In Notepad++, I compiled it correctly, I can see the exe on my desktop, but when I go to open it, it instantly closes out. Any Ideas?
Run it through command line.
Run cmd first, then navigate to your file and run it.
Or execute it from IDE of your choice. If you are not using one, start using it. It is really handy.
Visual studio is good, but I use Code::Blocks and i love it more than VS. You can download a version with all that good stuff already there, just open the IDE and start writing. If your interested in checking it out here is the link:
I have Microsoft Visual Studio 2013. So by using this I won't have to worry about compiling through G++ correct? However when I use Visual Studio I am still confused as to which form to use. Which one is most common, Windows Forms or console application? I am familiar with Visual Basic, is there a visual form editor for C++ as well?
Which one is most common, Windows Forms or console application?
Most guides and books will assume you are using console project as it is the most pure part of C++. After you get the grasp of the language, you can move on to 3rd party libraries e.g. graphical ones.
, is there a visual form editor for C++ as well?
Both Visual Studio and Borland C++ Builder provides one.
There is absolutely nothing wrong with your program.
The problem is this:
1. you click the exe
2. a console window is created and attached to the running exe
3. the exe prints your message
4. the exe terminates
5. 5the console window closes
6. this all happened so fast you saw just a flash, maybe
To run the program, you need to have an open console window.
1. Change to the folder your exe file is in (or, if it is on the desktop, minimize everything so that the desktop has focus)
2. Hold down Shift and press the Menu key (on the right side of the keyboard between the Windows key and the Ctrl key)
3. Then press 'W' and then Enter
4. Type the name of your exe file
Console applications are designed to run from the console. Double-clicking it from explorer is not running it from the console.
When you double-click a exe designed to run from the console, Windows is smart enough to create and attach a console window to the process. But when your program is done, Windows figures you no longer need the console created for you, so it removes it.
To keep the console window open a little longer, your program should not terminate until the user is ready. Here's an old article (that I have yet to update) that discusses this: http://www.cplusplus.com/articles/iw6AC542/
Your other option is to create a link to your application that opens a console and then runs your application.
(Or you could just require/assume your users will run the program from the console they way it is designed to work.)