Sign in to follow this  
Followers 0
xantr3x

C++ Compiler

16 posts in this topic

I'm learning C++, and need a good compiler. Any suggestions/favorites?

Note: It has to be free

Thanks!

0

Share this post


Link to post
Share on other sites

I use gcc/g++, which is of course free. If you're using Windows, I believe you can run it under Cygwin.

0

Share this post


Link to post
Share on other sites

On windows, you should use the Borland C++ Compiler, which is pretty good. On *nix gcc is good.

0

Share this post


Link to post
Share on other sites

On windows, you should use the Borland C++ Compiler, which is pretty good. On *nix gcc is good.

I tried Borland, but it said i didn't have the prereqs, but I did have them.

0

Share this post


Link to post
Share on other sites

I'm using the BORLAND C++ Personal Builder. Let me get you an advise, don't buy any Borland Product.

BECAUSE, mostly every code you'll find in the INet is not fully compadeble with the Borland Products, you'll have to change a few thinks @ the code everytime.

The best I think would be, if you get the C++ Dev by Microsoft (bit-cough-tor-cough-rent).

HaNoCr

(Sry for the bad English, ... but I'm very very tired. [Germany])

0

Share this post


Link to post
Share on other sites

If you're on Windows, just get an express edition of Visual C++ 2005, I think you still can get one for free with registration. Another option is Dev-C++. If you're on Linux or any UNIX, just go with g++. IDEs are of no use.

0

Share this post


Link to post
Share on other sites

Yep, I'm using Dev- C++

How do I see what the result of a program is?

When I hit execute, a cmd.exe window pops up and disappears.

0

Share this post


Link to post
Share on other sites

Yep, I'm using Dev- C++

How do I see what the result of a program is?

When I hit execute, a cmd.exe window pops up and disappears.

open a command window and execute the program from that. working from an already open command prompt window means that you get returned to the command line after the executing of the program and can see the output, it also means you can send command line arguments to the program when executing it.

so basically:

open command prompt

traverse to directory with code in it

compile the code using the compile button in Dev-c++ (or Ctrl+F9)

then run the compiled program from the command prompt you opened

0

Share this post


Link to post
Share on other sites

You have to run it from the command prompt. Open the command prompt and use cd to get to the correct directory, then just type the program name. So something like:

C:\> cd ./my programs

C:\my programs\ >my_prog.exe

should work for what you want (just replace the bits with your file/directory names).

0

Share this post


Link to post
Share on other sites

Yep, I'm using Dev- C++

How do I see what the result of a program is?

When I hit execute, a cmd.exe window pops up and disappears.

Ahh, this is common problem on an ide, that is very easy to fix.

Lets say you are displaying "hello world" with this code:


#include <iostream>

using namespace std;

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

This will have a window pop up, and then close. Thats becuase you forgot the cin.get() fuction, which will let the window display until enter has been hit.

So the real code should look like this:


#include <iostream>

using namespace std;

int main()
{
cout<<"Hello World!\n";
cin.get();
}

Sorry if this isn't accurate, I haven't used C++ in a while.

But I recommnd C, C++ will confuse/frustrate you, becuase it actually is harder.

You don't have to, but I recomend switching to C, use a gcc compilier.

You use ubuntu right? You can go to Settings>Administration>Synaptic Package Manager, and download gcc from there.

afterward, go to Programs>acessories>terminal

and type

man gcc

If a man page comes up, you have installed it correctly. You don't have to, but I recomend reading the man.

Now you need to write a C program. So press q and quit man.

Now type:

vim hello.c

if it comes up with an erorr, try

vi hello.c

Though vi isn't as good, you can use it. I recomend using vim. Go to synaptic package manager sometime and install it.

or you could open up a GUI text editor and do it from there.

If you want to use vi, in that terminal that you have running, make a directory Programing. To do this:

mkdir Programing

Then

cd Programing

Now it is time to make the c file

vi hello.c

A blank terminal pops up? Yes.

Type i and enter insert mode. And why I like vim, if you make a typo you don't have to press ESC and then x to backspace.

Now type:

#include <stdio.h>

int main()
{
printf("Hello world\n");
}

Now press ESC to exit insert mode, and write the file with a press of w , and then quit with q .

Or you could make a text file with a GUI text editor.

Go to Programs>Acessories>Text editor and copy this in:

#include <stdio.h>

int main()
{
printf("Hello world\n");
}

And save it as hello.c in the directory Programs.

Now get back to that terminal thats in Programs, and if it isn't,

cd Programs

Make sure all the files are there by listing them with ls . If you see hello.c , Then you did good.

Now you have to compile, link and execute.

Compile:

gcc -c hello.c

That compiles the program hello.c . The -c function meaning compile. If you read the man page you would already know this.

Link:

gcc -o hello hello.o

This links the program, and makes an executable hello. If you want the executable to be named asdf, then just replace asdf with hello.

Execute:

./hello

This executes the program. You should see Hello world pop up.

That is how you can use the gcc compilier.

As for a book on C, Beginning C By Ivor Horton should work fine.

If you don't want to learn C, thats fine, but it is just easier for people that are just starting off.

Edited by Octal
0

Share this post


Link to post
Share on other sites

I don't know for Dev-C++, but Visual Studio has a way to lauch your program adding a pause at the end of it (ctrl+F5), as I described here in my tutorial:

http://www.planetcpp.info/appendixA3.html

Just check for Dev-C++, there is probably a way to launch your program with a pause at the end. Otherwise, just add a system("PAUSE");, it will do the same.

0

Share this post


Link to post
Share on other sites

Thanks Octal, now I may gaze upon those glorious words. "Hello world!" Ah, how beautiful it is.

I'll stick with C++, I like a challenge.

And no, I'm not running Ubuntu, sadly. I'm using Fedora on my box.

0

Share this post


Link to post
Share on other sites

Thanks Octal, now I may gaze upon those glorious words. "Hello world!" Ah, how beautiful it is.

I'll stick with C++, I like a challenge.

And no, I'm not running Ubuntu, sadly. I'm using Fedora on my box.

Ahh, I remeber you saying you are installing ubuntu, and dual booting windows.. I guess you switched.

Edited by Octal
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0