How to open c++ using the command prompt so that I can start programming in c++?

Thanks!

Dani AI

Generated

You do not open C++ in cmd; you use cmd to run a compiler. is right that edit is just a text editor. On most modern 64-bit Windows versions, edit is not available, and that old C:\TC (Turbo C/C++) toolchain targets DOS and is unsuitable for modern C++. Use a current compiler and keep source files in a normal folder (e.g., C:\code\hello).

A minimal workflow that works entirely from the command line:

  1. Create a file hello.cpp with any editor (Notepad works fine):
#include <iostream>
int main() {
    std::cout << "Hello from C++!\n";
}
  1. Pick one compiler path:
  • Microsoft C++ (MSVC): open the "x64 Native Tools Command Prompt for VS" so cl is on PATH, then:
where cl
cl /EHsc /W4 hello.cpp
.\hello.exe
  • MinGW-w64 g++: ensure C:\mingw64\bin (or your chosen MinGW path) is on PATH, then:
where g++
g++ -std=c++17 -O2 -Wall hello.cpp -o hello
.\hello.exe

Tips and gotchas:

  • If a console window opens and closes instantly when you double-click an .exe, run it from an already-open cmd or PowerShell (.\hello.exe) so you can see the output. , the output only "appears in cmd" if you actually run it from there.
  • If cl or g++ is "not recognized", your PATH is not set or you are not in the correct developer prompt. where cl / where g++ helps confirm setup.
  • Prefer current C++ standards (e.g., -std=c++20) and avoid legacy Turbo C compilers to ensure modern language and library support.

Recommended Answers

All 4 Replies

You don't "open" c++ in the command line. You edit your programs in a text editor like WordPad/Notepad or in an IDE (much better choice due to syntax highlighting and automatic indentation).

Try this IDE if you're just starting out: codeblocks

Just remember that you'll need to have not just the IDE, but also a compiler. You can download codeblocks with the compiler included. It's the option labelled: "codeblocks-8.02mingw-setup.exe" (where mingw is the Windows port of the gcc compiler).

You can then compile your programs right within the IDE or you can do so from the command line (so long as gcc is in your PATH) using: g++ myProgram.cpp -o myProgram.exe

Hope this helps.

Thanks necrolin, can I use this at command prompt?

C:\>cd tc
C:\TC>edit

Is it possible for me to write my code from there?
Thanks.

You can use the editor "edit" if you like. Again, it won't be nearly as convenient as something designed specifically for programming, like Code::Blocks, but that's your choice.

As far as directories go I suppose there is nothing stopping you from using the tc directory. However, I believe that the best place for your files is to place everything in "My Documents". You can always place a directory like "Programs" or something in your documents folder and just compile everything from there.

Not sure if you have a compiler installed on your computer. If not, you'll need one to convert your code into an actual runnable program. The GCC compiler can always be downloaded from http://www.mingw.org/ if need be.

Its not hard and i only started learning C++ in november this year! You just code it and will appear in command prompt (cmd), unless you want to create a new window, which is more complex. If we helped, click solved thread!

Hope I helped you, mate!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.