# Turbo C++



## RAMAddict (Jul 7, 2004)

Hello. In school we use a program called Turbo C++ to compile C++. I looked for the program on the internet and I only can find the download for the really old one. Anyone know where I can get this? Or another good free C++ compiler?


----------



## Chicon (Jul 29, 2004)

Hi RAMAddict,

It seems that Borland has not released a most recent version of Turbo C++.
Instead of using Turbo C++ at home, you may use Dev C++ free download from
http://www.bloodshed.net/devcpp.html
It works nicely. :up:


----------



## RAMAddict (Jul 7, 2004)

Thanks


----------



## RAMAddict (Jul 7, 2004)

Any other compilers other than Dev C++ because that program keeps giving me errors and it won't run correctly when I write a simple Hello World program.


----------



## jamesh2923 (Aug 22, 2004)

RAMAddict,

Although Turbo C++ is a little long in the tooth, it is an excellent compiler.
And, as a learning tool really very good. 

A version of Turbo C++ is included with DiskTutor C++.

Check EBay for someone willing to sell their copy of Turbo C++.

The other thing to do is buy MS Visual Studio which will allow the development
of high grade C++ based Windows apps. MSVS also has an excellent tutorial.


----------



## RAMAddict (Jul 7, 2004)

any other free compilers anyone knows about? what do you guys use? I really would like to find one. Please help. I tried searching google and I didn't find any good ones. Dev C++ doesn't read certain syntax's and stuff sometimes. Anyone else know any other ones?


----------



## IMM (Feb 1, 2002)

http://www.thefreecountry.com/compilers/cpp.shtml

For windows the borland is good but is command line and you will have to add your own IDE - there are several out there which work with it

It depends on your level and what you need
Digital Mars might be a thought ?


----------



## RAMAddict (Jul 7, 2004)

well I'm just beginning with C++ in school we use Turbo C++ and that program seems very simple to work with. Dev C++ looked good but it has syntex problems and junk.


----------



## RAMAddict (Jul 7, 2004)

ok whats wrong with this simple hello program?
I know for a fact that its correct but Dev C++ has a problem with it.

//My first C++ Program
#include<iostream.h>
main()
{
cout<<"Hello World";
return 0;
}


----------



## Shadow2531 (Apr 30, 2001)

It's not correct.

MinGW (the compiler DevC++ uses) doesn't allow you to get away with specifying main without an int type and using deprecated headers. Also the return line is not needed at the end of a c++ program. When main() completes its tasks, things in it are automatically destructed, so although you can explicitly specify the return line, there's no need to. Also, whenever possible, end your cout stream with an endl to flush the stream buffer.

Here.


```
#include <iostream>

using namespace std;

int main() {
    cout << endl << "Hello World!" << endl;
}
```


----------



## RAMAddict (Jul 7, 2004)

RAMAddict said:


> ok whats wrong with this simple hello program?
> I know for a fact that its correct but Dev C++ has a problem with it.
> 
> //My first C++ Program
> ...


I learned that in school. We used Turbo C++ and thats what he tought us and it worked.


----------



## Shadow2531 (Apr 30, 2001)

I'm in no way a "know-it-all" and don't want to come off like that, but he is starting you off with bad, bad habits that you'll only get away with if the compiler lets you.

If your instructor/teacher truly doesn't know how to do it properly(appears that way), you can show him the proper way to do it. Any good instructor/teacher will take a look at what you present to them, investigate it and decide if it is truly correct.

If your instructor requires you to have the return line just add it to my first example.

Or, at least do it like this (without the using namespace std line)


```
#include <iostream>

int main() {
    std::cout << std::endl << "Hello World" << std::endl;
    return 0;
}
```
A thing to keep in mind with programming.

Just because it works/compiles, doesn't mean it's right.

Also, keep in mind iostream.h is not even an existing file in modern compilers anymore. iostream (no extension) is what you use.

You can also goto http://www.nuwen.net/ and see what I mean. The first things posted show the proper way to do it.


----------



## RAMAddict (Jul 7, 2004)

Oh, so how do I know whats right? I mean I thought I would be learning the correct stuff in class. Its an Intro to C++ class.

See in here:
http://cprogramming.com/compiler.html

It shows the way I did it except it has int main() like you said.

Hmmmm.


----------



## Shadow2531 (Apr 30, 2001)

Read http://www.cplusplus.com/doc/ansi/hfiles.html .

That will explain.

At the bottom, on the right, is the ancient way of doing things, which you want to avoid.

It's 2004, use the method on the left.

(If you were wondering if the missing *int* was your main problem; yes it was.)


----------



## RAMAddict (Jul 7, 2004)

Thank you. I will look through it. I'm not saying your wrong or anything I'm just confused and I want to see which is the correct way and junk like that. Do you use Dev C++?


----------



## Shadow2531 (Apr 30, 2001)

As said on that page, the ansi c++ and pre-ansi c++ methods are technically both correct, but the pre-ansi c++ should not be used because it's too C-like and deprecated. In this day and age, we follow standards and when using c++, we use c++ methods and not c-like methods. If you want to follow standardized c++, you should do as I suggested in my first post to this thread. If you don't want to follow standards, use your instructor's method.

Either way you do it, you need to have the int part.

I used to use DevC++ till I realized it was making me ignorant. (Didn't even know what command to type to build a program). It's a horrible IDE and very unproductive IMHO. I prefer EditPlus (a text editor) to type the code and save it as file.cpp. Then type the commands to compile.

DevC++ is just an ide anyway and not a compiler.

www.mingw.org is where you will find the compiler that I use and the DevC++ ide uses.

I use MinGW + MySys for the command shell, where I type my commands/user makefiles.


----------



## RAMAddict (Jul 7, 2004)

Yea today I looked at the copyright for that program and it was made in 1991 or something like that. What I don't get is if the school just updated to Windows XP why they didn't update the C++ compiler and why are we learning the older way instead of the new way?


----------



## Shadow2531 (Apr 30, 2001)

See what you can do about getting them to change to something not so ancient.

Since they will probably be looking for simplicity of installation and of course free, you may be able to get them to use MinGW (with or without DevC++)

There is a good distro of MinGW(gcc 3.3.3) already setup.

If you goto http://www.nuwen.net/ , click on the c++ link and then download mingw.zip on that page. View the readme for how to set it up.

It's really simple to set up on XP and should also be easy to distribute and setup on the XP computers in question.

Once you have things setup and the mingw bin directory is in the path, to compile, you just do

g++ -Wall -W file.cpp -o file

(You would create your programs in a text editor or you can setup DevC++ to use this distro or the distro that comes with Devc++)

They may not do it, but it wouldn't hurt to ask.

You can point them to this thread or at least to http://www.bloodshed.net/ .

You'll be do others in your class a favor too.

If everything fails, you can at least use Devc++ out of class.


----------



## RAMAddict (Jul 7, 2004)

Ok I downloaded MinGw I'm confused though how to set it up. Can you give me step by step directions on how to set it up? Than how to use it? Thank you so much in advance


----------



## Shadow2531 (Apr 30, 2001)

If you are referring to the MinGW distro at nuwen.net.. then here's what you do.

unzip mingw.zip and put the MinGW folder in the root of your hard drive. (I will assume c.

If g++.exe is located in c:\MinGW\bin , then you most likely got it right.

Now under

control panel
system properties
advanced tab 
environment variables
system variables

add *;c:\MinGW\bin* to the end of PATH variable.

Then create a new system variable *RM* and set its value to *del*

Then it's all setup.

Then just load cmd.exe (command prompt)
change to the directory where you saved the .cpp file.
type the following command.

g++ -Wall -W *file*.cpp -o *file*

That will produce *file*.exe

To make the exe smaller, use this command.

g++ -Wall -W *file*.cpp -o *file* -s && upx --best *file.exe*

If you need to do this on win9X/ME, it's the same except you set the path differently. (just let me know)

-Wall and -W turn on almost all warnings.

-o and the following filename is tells the compiler to output to that specified filename

-s strips debug info and makes the exe smaller
upx --best is an exe compresser. (Makes the filesize even smaller).

DevC++ just does these commands for you. That's all it does.

Save the following as hello.cpp to your desktop. (make sure to leave a blank line at the end of the file.)

```
#include <iostream>

using namespace std;

int main() {
    cout << endl << "Hello World!" << endl;
}
```
Load a command prompt and switch to your desktop. If it doesn't already load in your desktop directory, modify the shortcut so that it does.

Then type.

g++ -Wall -W hello.cpp -o hello -s && upx --best hello.exe

When it's done, while still at the command prompt, type *hello*.

That will run hello.exe


----------



## RAMAddict (Jul 7, 2004)

Yea I have Win 98 I can't find the system properties


----------



## Shadow2531 (Apr 30, 2001)

Here's the command to add mingw to the path.

*set PATH=%PATH%;c:\MinGW\bin*

You can do that lots of ways, but here's 2.

add that line to your c:\autoexec.bat file. (restart to take effect)

or

type that command every time you load command.com

With win98, you might have to use the following in autoexec.bat instead if "set path" doesn't work.

*PATH=%PATH%;"c:\MinGW\bin"*


----------



## RAMAddict (Jul 7, 2004)

yea but see where do I put PATH = %PATH%;"c:\MinGW\bin"?


----------



## Shadow2531 (Apr 30, 2001)

The line might need to be

*PATH c:\mingw\bin;%PATH%* instead.

edit c:\autoexec.bat with notepad and add that as a line.

or

start
run
msconfig
autoexec.bat tab

and add it that way.


----------



## Shadow2531 (Apr 30, 2001)

If that doesn't work, you can do it like this

open notepad and put the following lines in it.

@ echo off
Set PATH=C:\MinGW\bin;%PATH% 
cd C:\windows\desktop

Save it as mingw.bat to c:\windows . Once it is there, right-click on it and choose "create shortcut". cut the shortcut and paste it to your desktop. right-click on the shortcut, left-click on properties, switch to program tab, modify the target to :

command.com /k mingw.bat

Then whenever you need to use mingw, just double-click the shortcut on your desktop.

To test that it works, type *g++* and press enter. It should sayt "no input files".

If it does, you got it working.

The autoexec.bat way will be best though.

if command.com /k mingw.bat doesn't work for the target, try

%comspec% /k c:\windows\mingw.bat

for the target.

If you need another set of directions to show you how to add to the path,

http://java.sun.com/products/archive/j2se/1.2.2_008/install-windows.html#Environment

(I don't have win98, so can't check for sure.)

I myself just double-click a batch file to load a command prompt where MinGW is in the path.

[mingw.bat]
@echo off
%COMSPEC% /K "set PATH=%HOMEDRIVE%\mingw\bin;%PATH% && set RM=del && cd %HOMEPATH%\desktop"

Just not sure if that will work on win9x/ME.


----------



## RAMAddict (Jul 7, 2004)

ok that works but now how do I compile a program with it? Sorry for being a pain.


----------



## Shadow2531 (Apr 30, 2001)

note: I tend to edit my posts quite a bit sometimes, so always check them again from time to time.

Post #20 in this thread explains how to compile.


----------



## RAMAddict (Jul 7, 2004)

Save the following as hello.cpp to your desktop. (make sure to leave a blank line at the end of the file.)

Code:

#include <iostream>

using namespace std;

int main() {
cout << endl << "Hello World!" << endl;
}

Load a command prompt and switch to your desktop. If it doesn't already load in your desktop directory, modify the shortcut so that it does.

Then type.

g++ -Wall -W hello.cpp -o hello -s && upx --best hello.exe

When it's done, while still at the command prompt, type hello.

That will run hello.exe

I tried that and it says no such file or directory


----------



## Shadow2531 (Apr 30, 2001)

c:\mingw\bin must not be in the path then. (unless win98 is just goofy like that)

Review my last few posts and try some of the other suggestions.

Also keep in mind that win98 might not handle longs paths that well.

You can try creating a new directory c:\work

save you .cpp files there and go to the directory via the command prompt and try.

On win2K and XP the whole process of adding to the path variable is super simple.


----------



## RAMAddict (Jul 7, 2004)

Thank you very very very much for helping me and giving your time up. 

I just have one more little question. When the compiler loads the program it doesn't stay it pops up and than leaves. I was reading about this before that some compilers do that and Ihave to insert this code into it but when you type that code up it didn't have that code so I'm assuming this doens't happen to you. How do I stop it from popping and leaving?


----------



## Shadow2531 (Apr 30, 2001)

I take it you got it to work?

If so, please post the Path line you used in your autoexec.bat file so we can have confirmation. (For others that may read this thread and have win98).

As for the program popping up and exiting right away, it's supposed to do that. Command line programs are supposed to be loaded from the command line.

So you normally you don't want to double-click the file, you want to load a command prompt and type file.exe to load it.

However, if you want to stop it from dissappearing when you double-click it, you can use a pause or wait for input.

#include <cstdlib>

and for the last line in your program, use

system("pause");

Keep in mind that linux doesn't have "pause" so that would only work on windows.

Instead you can use

cin.ignore();

at the end of the program. Pressing enter will exit.


----------



## Shadow2531 (Apr 30, 2001)

It's not necessary to upgrade your mingw 3.3.3 distro yet, but just letting you know that 3.4.1 and 3.4.2 release candidates are out.

Check http://www.nuwen.net/ from time to time because there will be a new distro offered soon. It will be a 3.4.2 distro.

Not to get ahead of you, but if you wanted to make your own distro, you can get the files here
http://sourceforge.net/project/showfiles.php?group_id=2435


----------



## RAMAddict (Jul 7, 2004)

@ echo off
Set PATH=C:\MinGW\bin;%PATH%
cd C:\windows\desktop



REM To make a DOS Boot Diskette; See the file C:\DOSBOOT\DOSBOOT.TXT

path C:\WINDOWS;C:\WINDOWS\COMMAND;C:\PROGRA~1\GRISOFT\AVG6
SET BLASTER=A220 I5 D1 T4



@ echo off
Set PATH=C:\MinGW\bin;%PATH%
cd C:\windows\desktop


Thank you so much for your help!


----------

