Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run C++ in command prompt - Windows

I know that everyone uses an IDE nowadays, but I just find it simpler to write my code in notepad++, compile it using a command prompt command, and run it from there too. At least that works for Java and Python. I've tried to get my head around how to do that with C++, and haven't been able to find anything good. Is there any compiler (like Java's JDK) that I can stick into my path and use the C++ equivalent of javac and java to run and compile my code from CMD?

Note: please don't post answers and comments about how IDEs are better - I know they are. I'm just used to doing it the old way :D

like image 765
Bluefire Avatar asked Jul 06 '12 16:07

Bluefire


People also ask

Can I run C in command prompt?

To do this, press the Windows key, type cmd , right-click Command Prompt, and then select Run as Administrator. Once the prompt window is open, double-check that the compiler installed properly (and that the environment variables are set) by running the command gcc -- version at the prompt.

What is C in Windows command line?

The cmd or cmd.exe is the MS-DOS command prompt. The cmd is executed when the MS-DOS or command prompt started in Windows. The “cmd /c” is a popular usage where the “/c” is provided to execute a specified string as a command in MS-DOS. After the provided command execution is completed the created shell will be closed.


1 Answers

Steps to perform the task:

  1. First, download and install the compiler.

  2. Then, type the C/C++ program and save it.

  3. Then, open the command line and change directory to the particular one where the source file is stored, using cd like so:

    cd C:\Documents and Settings\... 
  4. Then, to compile, type in the command prompt:

    gcc sourcefile_name.c -o outputfile.exe 
  5. Finally, to run the code, type:

    outputfile.exe 
like image 149
codeDEXTER Avatar answered Sep 26 '22 20:09

codeDEXTER