Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

C++ probs

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
youlikeicecream
LXF regular


Joined: Fri Jun 03, 2005 12:40 pm
Posts: 721
Location: Oxford

PostPosted: Wed Jun 22, 2005 5:54 pm    Post subject: C++ probs Reply with quote

Hi, bit new to C++ ... have written simple programs in C and compiled them on a remote UNIX shell using CC before but now when I try to compile programs on my Linuxbox at home It basically wont compile a damn thing. Here is the code I am using ....

***********************************************

#include <iostream.h>

main()
{

cout << "Hello World! ";
}

**********************************************

--- I type (as root) :

# gcc hello.c -o helloprog

--- and get these errors :

hello.c:1:22: iostream.h: No such file or directory
hello.c: In function `main':
hello.c:6: error: `cout' undeclared (first use in this function)
hello.c:6: error: (Each undeclared identifier is reported only once
hello.c:6: error: for each function it appears in.)

also I did a quick search for iostream.h and found it under /usr/include/c++/3.3/backward/iostream.h

but I still got the same error message that it could not be found!!

can anyone help? Am I doing something really stupid or is something improperly installed?

thanks
Mike Smile
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
wiz
LXF regular


Joined: Thu Apr 07, 2005 7:20 pm
Posts: 119
Location: In front of a computer

PostPosted: Wed Jun 22, 2005 6:58 pm    Post subject: Reply with quote

Try using

g++ hello.c -o helloprog

I think you need the the c++ compiler.
Back to top
View user's profile Send private message
1slipperyfish
Forum Jester


Joined: Mon May 09, 2005 3:52 pm
Posts: 2429
Location: wigan

PostPosted: Wed Jun 22, 2005 7:37 pm    Post subject: Reply with quote

i used
Code:
#include <iostream>

main()
{

std::cout << "Hello World! ";
}

saved it as hello.cpp in /home/paul
then complied it as g++ -o hello hello.cpp (as root) and ran it with ./hello
i am no expert but the compiler you said you used at work is probably an older one as not all compilers will accept the ".h" part
plus you had missed off the std:: part the only way around that would be to put using namespace std; under #include....(but i wouldn't if you are new to c++) as this is older c++ as is .h
hope this helps
paul
_________________
i am a follower of the culture



Last edited by 1slipperyfish on Wed Jun 22, 2005 7:50 pm; edited 3 times in total
Back to top
View user's profile Send private message
alloydog
LXF regular


Joined: Thu Apr 07, 2005 8:32 pm
Posts: 600

PostPosted: Wed Jun 22, 2005 7:43 pm    Post subject: Reply with quote

Also, try losing the .h from the iostream
I found this with g++. I got the message that the .h has been depreciated, but it still compiled, after I ignored the warning. Rerunning the compiler with just #include <iostream.h> worked fine with out any messages.

For C++, don't you need to save the inital file with the extention .cpp?

It seems nearly every "Hello World" tutorial is different! As one of the more recent one's followed gave:
Code:
#include <iostream>

using namespace std;

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


Then it's compiled with:
g++ hello.cpp -o hello
Back to top
View user's profile Send private message
youlikeicecream
LXF regular


Joined: Fri Jun 03, 2005 12:40 pm
Posts: 721
Location: Oxford

PostPosted: Thu Jun 23, 2005 11:30 am    Post subject: Reply with quote

I managed to get Kdevelop to compile a simple KDE application after installing a whole heap of stuff but I cannot get a single peice of my code to run.

Thanks for the info guys Smile

Mike Smile
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
1slipperyfish
Forum Jester


Joined: Mon May 09, 2005 3:52 pm
Posts: 2429
Location: wigan

PostPosted: Thu Jun 23, 2005 7:18 pm    Post subject: Reply with quote

Quote:
hello.c:1:22: iostream.h: No such file or directory
hello.c: In function `main':
hello.c:6: error: `cout' undeclared (first use in this function)
hello.c:6: error: (Each undeclared identifier is reported only once
hello.c:6: error: for each function it appears in.)

as far as i know the line 1:22 is because as i said it is an older version of c++ that was a crossover from c
the other errors are for the line
Code:
 cout << "Hello World! ";
as you have not used
Code:
std::cout <<"paul is great";
that is all your errors mean (as they are all on line 6) another tip to avoid compiler errors is to press enter after your last bracket before you save it, otherwise you will get sometihng like " no newline at file end" or words to that effect
hope this helps
paul
_________________
i am a follower of the culture

Back to top
View user's profile Send private message
otrus



Joined: Mon Jan 02, 2006 1:11 am
Posts: 5
Location: Norway

PostPosted: Mon Jan 02, 2006 1:48 am    Post subject: Reply with quote

I had a similar problem. When I compiled using 'gcc -o hello hello.cpp' it returned a whole lot of errors. However, when I used 'g++ -o hello hello.cpp' it worked perfectly well. I tried using the '-x c++' option to specify c++ as the language, but that didn't work either. After a bit of research I found out that gcc didn't link to the c++ library, and even thogh I tried to explicitly specify the library I never got it to work. I probably didn't install the library properly.

Anyway, that's not a big problem since I can just use 'g++' to make everything work.
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast