How to use MS Command Prompt to run source code created on notepad.

Hey

In my programming course a substitute came in and stated rambling about how he only teaches his students to program C++ using DOS/MSDOS/COmmandPrompt.

(Side-quest: what is the difference between DOS, MSDOS and CommandPrompt?)

Anyway, i would like to learn how to do this! I think it would be really cool to just open up the Command Prompt and start typing code right from there instead of loading up Visual C ++ , saving directories and root folders, compiling and then running code. Even if using Visual C++ is more practical, id like to know how compiling from the Command Prompt works.

Anyone?
what is the difference between DOS, MSDOS and CommandPrompt?
It's probably easier to describe what they are.

MS-DOS is a 16bit single user/single tasking operating system developed in the 80s to run 16bit PCs. It is a text based operating system.

DOS is a synonym for MS-DOS. The actual name is not relevant to this use.

Command Prompt is the console shell in Windows. It's a Windows application that simulates the MS-DOS environment. It's beefed up a little, so it a bit nicer to use than MS-DOS ever was.

i would like to learn how to do this!
Here's a command list. You might have to search for a tutorial.
http://ss64.com/nt/

id like to know how compiling from the Command Prompt works.
Your Visual Studio installation will provide an environment variable that points to the installation. You can see environment variables by typing set.

The computer I'm using has Visual Studio 6, 2005, 2008 & 2010 installed and my environment has these variables:
1
2
3
4
VS100COMNTOOLS=C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\
VS60COMNTOOLS=C:\Program Files\Microsoft Visual Studio\Common\Tools
VS80COMNTOOLS=C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\
VS90COMNTOOLS=C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\


Let's say I wanted to use Visual Studio 2005 to compile a program, here are the steps.

1. Type "%VS80COMNTOOLS%vsvars32.bat"
This sets up the necessary environment variables that you need to use Visual Studio 2005.

2. Type notepad hello.cpp

3. Enter this program into notepad and save and exit when done.
1
2
3
4
5
6
7
#include <iostream>

int main()
{
    std::cout << "hello world" << std::endl;
    return 0;
}

4. Type cl hello.cpp
This compiles the code.

5. Type hello
This runs the program.
@kbw

Wow thanks a lot that's a huuge help!! Im gonna start experimenting with this right away!
Let us know how you get on.
DOS is a synonym for MS-DOS

That's not entirely true. When people refer to DOS, they usually mean MS-DOS, but there were other DOS operating systems. IBM supplied PC-DOS, and a popular alternative at the time was DR-DOS.

DOS itself was not really text based. It was a minimal operating system providing an API to a disk file systems, memory management, and process loading and execution, and a few other related services. COMMAND.COM was the character mode command interpreter that most people think of when they hear the term DOS, which the current Windows Command Interpreter is based on (functionally that is. The program itself is an ordinary Win32 executable). It was not really essential, and was easily, though rarely, replaced.
Last edited on
@DeadSun511
You might also like to try GNU C++ Compiler. I guess g++ users use the command line (when compiling) more than vc++ users.
http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

kbw wrote:
The computer I'm using has Visual Studio 6, 2005, 2008 & 2010 installed
Don't you experience compatibility issues or something like that? I have Visual Studio 6 and 2008 installed, and whenever I run Visual Basic 6, it always shows an installation setup. It's so annoying. And also other sort or problems.
I have Visual Studio 6 and Visual Studio 2008 installed on most of my computers blackcoder, and haven't seen any of the behaviors you mentioned. Sounds like something went fluey with your installation.

If the original poster is interested, quite a while back I posted a rather detailed blow by blow Windows GUI command line compiling mini-tutorial here for meesa using the GNU compilers. I could likely find it. It was about a year ago.
codeFoil
That's not entirely true. When people refer to DOS, they usually mean MS-DOS, but there were other DOS operating systems. IBM supplied PC-DOS, and a popular alternative at the time was DR-DOS.
IBM-DOS was a licenced MS-DOS. I don't recall anyone at the time calling DR-DOS DOS, it was always referred to as DR-DOS. There was also another DOS that had a different disk layout than MS-DOS, but I don't remember the details. It was a long time ago, I dunno; I started using MS-DOS at version 2.1. I dunno what happened before that.

The name DOS goes back to IBM mainframes in the 60's, but in the 80's when PC's were current, DOS usually meant MS-DOS.

blackcoder41
Don't you experience compatibility issues or something like that?
I only use C++ from Visual Studio, not VB. I've not had any compatibility issues with having multiple versions of Visual C++ installed as long as you install them in version order :)
Topic archived. No new replies allowed.