1.11M Members

How to run c++ program through command prompt?

 
0
 

Well i use Dev-c++ 4.9.9.2 for programming..i m using it from last two years...recently i learned java and saw that all java programs are run through command prompt. I tried tha same in c++. i saved my program in dev-cpp/bin .but i am not able to do this..what is the exact procedure please tell me.. and How to pass command line argument. Is there any limitation on the type of arguments passed to main. like i saw somewhere int main(int argc,string args[])

 
0
 

Here's a couple links to command line argument help:
http://malun1.mala.bc.ca:8080/~wesselsd/csci161/notes/args.html
http://www.cprogramming.com/tutorial/lesson14.html

As to running your program, be sure you opening the command window in the folder where the .exe file is located. That's the file you execute as in

c:\dev-cpp\bin\> myprog.exe 

If you are unfamiliar with working at the command prompt, here's some help:
http://www.claymania.com/dos-primer.html

Val

 
0
 

thanks for the links...they are really useful...
but my problem is that i dont know what are commands to compile and run the cpp program..

ok see
steps are
1.save file in bin
2.run command prompt
3. type in cd c:\dev-cpp\bin now i m in the same directory where the compiler and the program is saved...

now what next to compile my porgram named test.cpp

in java i know those commands they are

cd c:\program files\java\jdk1.5\bin
c:\program files\java\jdk1.5\bin> javac filename.java
c:\program files\java\jdk1.5\bin> java filename this is a test program

...
output

the line THIS IS A TEST PROGRAM in the third line is a command line argument..

i wanna know the cpp equivalent for this..

 
0
 

on linux, i would do

# g++ -o foo foo.cpp
# ./foo this is a test program
 
0
 

thanks for the links...they are really useful...
but my problem is that i dont know what are commands to compile and run the cpp program..

ok see
steps are
1.save file in bin
2.run command prompt
3. type in cd c:\dev-cpp\bin now i m in the same directory where the compiler and the program is saved...

now what next to compile my porgram named test.cpp

in java i know those commands they are

cd c:\program files\java\jdk1.5\bin
c:\program files\java\jdk1.5\bin> javac filename.java
c:\program files\java\jdk1.5\bin> java filename this is a test program

...
output

the line THIS IS A TEST PROGRAM in the third line is a command line argument..

i wanna know the cpp equivalent for this..

You don't have to compile it from the command prompt. In fact in the dev environment click the compile button (not the compile AND run button) and that will give you an executable. Then all you need to do navigate to that path using cd c:\dev and run your program from there.

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046139290&id=1043284392

 
0
 

@iamthwee

i know how to do it through dev environment...i just want to learn how to do it through command prompt

 
0
 

After creating the command prompt window you have to add the dev-cpp\bin to your PATH environment then execute make.exe

c:\Dev-C++:>make -f makefile.win <Enter>

The makefile.win should have been generated by the Dev-C++ IDE. If not, then you will either have to learn how to create it manually (its a big pain in the a**) or let the IDE do it for you. Alternatively you can type all the commands in the makefile yourself each time you want to compile the program -- which is another big pain in the rear.

 
0
 

Another way,(I'm in a programming class) is to download MinGW for your computer. I don't have the link ready on hand. But regardless, download MinGW and make sure you know which harddrive it downloads into (Commonly in C:\) then when in the Command Prompt, type in:

set PATH=C:\MinGW\bin

Exactly(PATH I'm not so sure about) go to the area where your file is located(in the command prompt). type in:

g++ (nameoffile.cpp)

Or just type the first few letter of the file name and hit TAB on the keyboard. The file name should appear and then just hit Enter/Start above the Shift Key.
Your program should start.

 
0
 

Thanks for your response to a three-year-old thread :)

For anyone else who stumples upon this thread, I don't recomment Dev-C++ any more because its a dead IDE and uses an old compiler. Get Code::Blocks.

 
-1
 

I was browsing for answers but just thought hmm....What about just add

/* "My Code...." */

This just comments everything between /* ..... */

Then remove /* .....*/ if I want to run the specific code later on.
That way you do not have to eliminate your old code by using Exclude From Project :)

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article