how to run C++ code in command line ?
compiler : DEV-CPP
how to run C++ code in command line ?
compiler : DEV-CPP
Do you mean you want to compile it at the command line or create a command line program?
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
yes, i want to compile and run in command line. i dont want to use IDE.
my compiler is DEV-CPP
Hello, I think there's a little confusion: devcpp is not a compiler, is an IDE; by default devcpp uses MingW to compile, so you can have a look at www.mingw.org in the section 'Documentation', subsection 'Compiling and building with...', where you will find the easy ways to doing it, different synthax to compile C, C++, outputs and other stuff.
Sorry to not post a sample way to do it, but I always use the IDE
Niara
Thanks for the information.
anybody here compile and run in command line . please give me a sample
Meh. Not too difficult.Originally Posted by Stream
Using a library (OpenGL for example):Code:g++ blah.cpp -o blah.exe
Code:g++ blah.cpp -lopengl32 -o blah.exe
DevC++ uses gcc (MinGW) for compiling, so it should already be installed on your system. Just add it to your PATH or cd to the dir it's in (C:\devcpp\bin?) and run it.
hi, i have added C:\Dev-Cpp\bin in my PATH variable.
after that how do i compile and run my cpp code ? my code is here c:\myfolder\Prog.cpp
please tell me the syntax of compile and run command line instructions.
Regards
Well at your command prompt, type
g++ prog.cpp
That should get you an exe file (prog.exe or a.exe say), which you then just run like you would any other program.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well at your command prompt, typeok.g++ prog.cpp
i did
Code:C:\>g++ prog.cpp C:\>
so, it compiled fine. but did not get a prog.exe in c:\.......rather i get a a.exe file !
and when i clicked a.exe....command prompt blinked away ...i could see nothing.
so,
Q1. how can i run the code (a.exe )?
Q2. i dont like my exe's name to be a.exe.........can not i get it with the name prog.exe ?
The same way you call any other executable. If you click the icon then a process is spawned and and console window created for the program to run in. When the program is done, the process is destroyed and the window along with it. To keep the window open, you need to keep the program running. The most common way to do that is a blocking read:Q1. how can i run the code (a.exe )?
Alternatively, you can run the program from the command line. That way the process and window belong to the command prompt, not the program, so it isn't destroyed when the program ends.Code:#include <iostream> #include <limits> using namespace std; int main() { // Your program here // Discard leftover characters in the stream cin.ignore(numeric_limits<streamsize>::max(), '\n'); // (Hopefully) blocking read cin.get(); return 0; }
a.exe is the default if you don't provide a name, just like on *nix it's a.out. You can change the name with the -o switch:Q2. i dont like my exe's name to be a.exe.........can not i get it with the name prog.exe ?
While you're at it, say -Wall and -pedantic too. Those switches help you catch bugs:Code:C:\>g++ -o prog.exe prog.cpp
Code:C:\>g++ -Wall -pedantic -o prog.exe prog.cpp
Just because I don't care doesn't mean I don't understand.