you need to add the compiler to the PATH variable, then in cmd prompt get to the folder where the .cpp file is saved and run it with the g++ (for compiler) -o (for make executable) prompts which will create the executable HelloWorld.exe from the source file HelloWorld.cpp. Then to run HelloWorld.exe from cmd just type HelloWorld (w/o the .exe)
This video explains it all in great detail https://www.youtube.com/watch?v=k3w0igwp-FM
Unlike code where you can post it online it's difficult to second guess your system configurations from here. But if you have a C::B with compiler then you need to include the location of this compiler in your your PATH variable- the video, around 4:40 into it, shows how. If you don't have a complier (but I suspect you do) then you can download one here for Windows: https://nuwen.net/mingw.html(download the smaller file, w/o git) and then pick up the video again from around the same time line. The main thing is to get the compiler location into your PATH variable.
If you're using Code::Blocks you don't need to do this. Instead you probably have a nice "compile" button that you can press.
You can of course do what the tutorial is telling you. After all, it's good to know how things work "under the hood" so to speak. But in that case you should open the command prompt from outside Code::blocks. Probably the easiest way is to press Windows flag+R, type "cmd" and press enter. That will open up a new command prompt window where you can type commands and it will not automatically close itself.
What command? No, none of the mentioned commands is.
(If you do mean the 'g++', it might refer to a program within GCC and GCC itself is older than Linux by many years. See https://gcc.gnu.org/wiki/History Besides, Linux kernel is only the kernel, not "commands" and furthermore the kernel is written in C rather than C++.)
StrawBerry Lips wrote:
the application closes down immediatley
When you do something in a terminal, the terminal will not close after a program quits.
However, when you let GUI execute a console app, the GUI starts a temporary terminal for the app and by default closes it when the app quits. A low-life workaround is to not quit the app immediately. See: http://www.cplusplus.com/forum/beginner/1988/
is interpreted by a shell (and not by any "kernel") to mean: look from current working directory a file named 'foo' and execute it, if possible
The dot refers to current working directory and the slash is a directory separator. Microsoft's command interpreters tend to use backslash as directory separator.
The 'foo' does not need to be a binary compiled from C++ sources. It does not even have to be a binary file; ASCII files are fine too, if the shell knows how to interprete them; a comment on first line of a file can tell the used interpreter (if not shell).
There are several different shells from various sources; in no way Linux-specific or related.
GunnerFunner I use windows 10 and I added a new path in the system variables did I do it finally right?It looks alot different than his path it is a buch variables on top of other variables.
well there's only way to find out, did it work?
The route to your PATH is Control Panel -> System -> Advanced System Settings -> Environment Variables -> System Variables -> Path -> Edit ...
Did you watch the video link I sent you, all this is explained quite clearly there?
OK, here's an example, when I launch the Command Prompt window the blinking cursor is initially at
C:\Users\gunnerfunner>
And my HelloWorld.cpp file is in the D drive root folder. So to go from C:\Users\gunnerfunner to D:\ I first type where the cursor is blinking:
d:
and now the cursor blinks next to
D:\>
this means now we're in the D:\ drive and if your HelloWorld.cpp file is in this folder and your compiler has been correctly added to PATH you can now type at the cursor:
g++ -o HelloWorld HelloWorld.cpp
If everything runs smoothly this will create an executable HelloWorld.exe - you can look into the D:\ folder yourself and check if this file has now appeared. If it has then you need to run it, so go back to D:\ in the Command Prompt window and simply type
HelloWorld
If everything's OK then you'll see the output of the program i.e Hello World! just underneath where you typed. Unlike within Code::Blocks program output does not appear in a new window, in this case its just a single line within the Command Prompt window