Okay. I have said code:

#include <iostream>

int main()
{
	std::cout << "This is a native C++ program\n" << std::endl;
	return 0;
}//main

How would I compile this from a standard DOS command line? I've searched all over google, and have yet to find an answer that explains things well.

Thanks,
Derek Elensar

Which compiler do you have installed?

You need to add the \bin directory of the mingw folder to your path. Ex: http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx for Windows 7.

Another thing you can do is make a shortcut to a cmd window that runs a batch file that sets the path for that window only:
(call it mingw.bat or something)

@echo off

set PATH=%PATH%;C:\yourmingwpathhere\bin
set PATH=%PATH%;%SystemRoot%\System32

Then, create a shortcut (right click on the desktop, new, shortcut) and put %COMSPEC% /k c:\yourbatchfilepath\mingw.bat (change the Start in: directory to wherever your code is, so it goes to that directory each time).

Then, once you have your file above saved as native.cpp (or something) invoke the compiler by typing g++ native.cpp -o yourexecname

Or use a makefile.Yes "makefile" with no extension.Edit it like this

## this is a comment
COMPILER=C:%programfiles%\gcc\bin\g++.exe ##or whatever the path is
myfile.exe : myfile.obj
   $(COMPILER) -omyfile.exe myfile.obj
myfile.obj : myfile.cpp
   $(COMPILER) -c myfile.cpp

The type make at the command line and it should compile.I don't really recall the command line arguments for g++ but with a bit of luck i may be close.

Thank you so much, you guys. You helped me fuigure out what I've beent ry8ing to find out for so long :)

You could also add a registry key to allow compiling by simply right-clicking on a .cpp file and selecting 'Compile This' (or whatever you want to call it).

To do this, open your registry editor Start > Run > type regedit (enter). Expand the folders HKEY_CLASSES_ROOT > * > shell. Now right-click the shell folder and select New > Key. Rename the newly created folder 'Compile this' and then right-click that folder and create another new key called 'command' (it must be called command). Select the command folder and double click the entry '(Default)' (over on the right). Change its value data to:
C:\MinGW\bin\g++.exe "%1"
If that's not the path to your g++ compiler, then correct it; if it has spaces, use quotes for the path as well. Close the registry editor and you should be good to go. Find a CPP file and use your new quick compile feature and it should output an executable file in the same directory called 'a.exe'. Don't forget to rename a.exe before compiling another program or it will be overwritten.

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.