tags:

views:

181

answers:

6

i know that is somehow near to question
http://stackoverflow.com/questions/3283060/question-about-command-line
but here i will be more deeply
so my project name of which is project3 is keeped at desktop like project3.txt how compile it from command line?please give me command for to do it and also if it will be usefull for you in code is such part

int a=atoi(arg[1]);
int b=atoi(arg[2]);

i am using win7

+1  A: 

Assuming Visual C++: There's information on running Microsoft's compiler from the command-line here.

If you're simply trying to run the application, you just type in the name of the executable to execute it at the command line.

Might I suggest if you're doing such simple scripts that you use an interpreted language such as Ruby or Python? It's really much easier unless you're constrained to use C++.

Andrew Flanagan
+1  A: 

From the VS Studio CMD Prompt

cl.exe source.cpp

See more on Compiler Command-Line Usage

Dave18
Depending on whether paths are set right or not, you probably also want to use a command problem which you started from the icon in the Visual Studio folder on your start menu
Will Dean
cl.exe project3.cpp?
i dont understand how? my project name is project3.txt and is at desktop then?
@davit-datuashvili First save it as project3.cpp then run the VS-Studio Command Prompt, set the path to desktop physical directory and then try the command-line i mentioned above.
Dave18
+2  A: 

Now, may I assume that you are also using VisualStudio ?

The C++ compiler is buried deep in your Program Files folder. (somewhere like C:\Program Files\Microsoft Visual Studio 9.0\VC\bin but that will vary with the version). You need that folder on your DOS PATH environment variable, plus the paths to the libraries & header files. These are set up by running the VCVARS32.BAT file (in C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools)

Then the basic form is :

cl myfile.cpp
James Curran
A: 

If you are writing C++ code, do not save your source files with a .txt extension. Use .c for C-language source and .cpp for C++. Some compilers can have problems if you use the wrong file extension.

Since you mentioned Windows, I will assume you are using Visual Studio. If this is the case here are a few links that might help you create a new project and compile your code. Some of these reference older versions of VS, but the general concepts still apply.

http://pdfcast.org/pdf/how-to-create-a-c-program-using-visual-studio

http://www.functionx.com/cpp/references/projectcreation.htm (VS instructions are towards the bottom)

http://web.sau.edu/lilliskevinm/C%2B%2BTutorial/dotNet/

If you are not using Visual Studio, please edit your question and include the name and version of your compiler.

bta
A: 

Start a VS2010 Command prompt:

Start->All Programs->Microsoft Visual Studio 2010->Visual Studio Tools->Visual Studio Command Prompt (2010)

Switch to your directory:

cd c:\Users\(your username)\Desktop

or

cd c:\Users\davit\Desktop

Compile the code:

cl (yourFileName).cpp

or

cl project3.cpp

Run the code:

(yourfilename).exe (arg1) (arg2)

or

project3.exe 7 8
Jess
it shows me dont find path
no everything is correct just it is David not davit in my computer
A: 

To run the Visual studio command prompt from the start menu:

Start_from_start_menu

Then the two options you probably want to use are either cl (labeled 2), to build a single C/C++ file, or msbuild (labeled 3), to build the whole project file you created with visual studio. You'll also probably want to change the initial directory, as shown in 1.

VS command prompt.

Please note that these images were taken using a localized version of Windows. You are looking for an option named Command Prompt. It is also using a project name of testApp, so if you're not using that, or you're not using the default file hierarchy that Visual Studio creates, you'll have to make sure the file paths are correct.

David L.-Pratte