Run C++ in command prompt - Windows

前端 未结 11 1622
逝去的感伤
逝去的感伤 2020-12-22 19:02

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

相关标签:
11条回答
  • 2020-12-22 19:29
    • first Command is :

    g++ -o program file_name.cpp

    • Second command is :

    .\program.exe

    Let us Check this image

    0 讨论(0)
  • 2020-12-22 19:30

    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
      
    0 讨论(0)
  • 2020-12-22 19:32
    1. Download MinGW form : https://sourceforge.net/projects/mingw-w64/
    2. use notepad++ to write the C++ source code.
    3. using command line change the directory/folder where the source code is saved(using notepad++)
    4. compile: g++ file_name.cpp -o file_name.exe
    5. run the executable: file_name.exe
    0 讨论(0)
  • 2020-12-22 19:32

    A better alternative to MinGW is bash for powershell. You can install bash for Windows 10 using the steps given here

    After you've installed bash, all you've got to do is run the bash command on your terminal.

    PS F:\cpp> bash
    user@HP:/mnt/f/cpp$ g++ program.cpp -o program
    user@HP:/mnt/f/cpp$ ./program
    
    0 讨论(0)
  • 2020-12-22 19:32

    This is what I used on MAC.

    Use your preferred compiler.

    Compile with gcc.

    gcc -lstdc++ filename.cpp -o outputName
    

    Or Compile with clang.

    clang++ filename.cpp -o outputName
    

    After done compiling. You can run it with.

    ./outputFile
    
    0 讨论(0)
提交回复
热议问题