LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ & linux - newbie (https://www.linuxquestions.org/questions/programming-9/c-and-linux-newbie-69997/)

crisponions 07-04-2003 01:39 AM

C++ & linux - newbie
 
I just started teaching myself c++ and have been doing most of my compiling on a windows machine. I thought I would give it a try with linux but am having problems.

The standard
#include <iostream.h>

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

wont compile. I have seen posts about dropping the h from the iostream and "include namespace std" but none of that seems to work either. I though c++ was supposed to be pretty platform independant. I really dont want to have to learn to code one way for windows and another for linux.

nakkaya 07-04-2003 01:53 AM

compiles on my machine code is correct what is the command u are using to compile

crisponions 07-04-2003 01:57 AM

just gcc. suing version 3.2.2-5

shellcode 07-04-2003 01:59 AM

g++ is the command you want to use.

crisponions 07-04-2003 02:06 AM

That did it thanks!

Cyclo 07-04-2003 01:49 PM

If you want to make GUI programs, try using Qt - free and simple :)

tcaptain 07-04-2003 02:37 PM

Quote:

Originally posted by Cyclo
If you want to make GUI programs, try using Qt - free and simple :)
QT is fun and simple enough (I'm learning it now...sort of...off and on) but I think it would be important to get the basic C++ down first before trying to use a toolkit like that so that you can understand how the toolkit is doing what its doing no?

Cyclo 07-05-2003 09:52 AM

my basis for recommending it is it drastically simplifies string handling etc, and it's tutorials are relatively good.

also, great book is "Learn C++ for linux in 21 days" :)

crisponions 07-05-2003 11:38 AM

I am using "teach yourself c++ in 21 days". But thanks for the info on qt, I will definately check it out once I get through the basics.

tcaptain 07-05-2003 09:13 PM

Quote:

Originally posted by Cyclo
my basis for recommending it is it drastically simplifies string handling etc, and it's tutorials are relatively good.

also, great book is "Learn C++ for linux in 21 days" :)

For THAT I agree...in fact I just managed to get my first QT project to work today so I'm pretty jazzed about it :D (Its just a dinky little thing but it's fun to work on...). I'm really liking the QString class now that I have the hang of it, although I stand by what I said, QT isn't for someone who doesn't know the basics...BUT, once you know..it's easy to get into...

A great book that I recommend (along with the others mentionned which I also have) is Tom Swan's 'GNU C++ for Linux'. Until I had found that book I had been rather frustrated by the windows-centric leanings of the other books (although that's a minor gripe since by and large, C++ is C++ for the basics). This book is totally awesome for the beginner programmer using linux. If you have to choose only one book, that's the one I'd go with.

mandolin 07-06-2003 02:42 PM

Well, I tried compiling your 'hello world!' code with gcc (>gcc test.cpp) and got a whole load of linker errors. I'm hardly an expert myself and I'm not sure why they're there.

Just using the c++ compiler worked fine (>c++ test.cpp), although you will need to add the 'using namespace std' into your code. That might do you for a while but you really should be able to use gcc.

What distro do you use (I'm using mandrake)?

Anyone else out there that's cleverer than me care to shed some light on the situation?

mandolin 07-06-2003 02:44 PM

wow, posts come thick and fast here don't they!

Proud 07-06-2003 03:45 PM

A 5.5 hour gap is fast? :confused:

crisponions 07-06-2003 06:19 PM

Quote:

Well, I tried compiling your 'hello world!' code with gcc (>gcc test.cpp) and got a whole load of linker errors. I'm hardly an expert myself and I'm not sure why they're there.

Just using the c++ compiler worked fine (>c++ test.cpp), although you will need to add the 'using namespace std' into your code. That might do you for a while but you really should be able to use gcc.

What distro do you use (I'm using mandrake)?
I am using RedHat 9. The g++ compiler took care of my problem.

So am I correct in assuming gcc is for c programs?

shellcode 07-06-2003 08:47 PM

Quote:

Originally posted by crisponions

So am I correct in assuming gcc is for c programs?

you are.


All times are GMT -5. The time now is 07:08 PM.