Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > 10.2 problems. Can't compile C++

10.2 problems. Can't compile C++
Thread Tools
Mac Elite
Join Date: Jul 2002
Status: Offline
Reply With Quote
Sep 5, 2002, 09:04 AM
 
I can't seem to get the new gcc3 compiler to work with my C++ programs. However, it does compile my C programs just fine. When I try and compile it reports cout, cin, and endl as undeclared functions. Whats going on?
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Sep 5, 2002, 03:19 PM
 
You might be having a namespace conflict. Try std::cout, std::endl, etc.

Or, bracket your code with 'using namespace std;'
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Thinine  (op)
Mac Elite
Join Date: Jul 2002
Status: Offline
Reply With Quote
Sep 6, 2002, 04:56 PM
 
I guess 10.2 uses iostream.h instead of the plain iostream like I had. Makes changing my files really easy at least.
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Sep 6, 2002, 07:15 PM
 
No, it should be just <iostream>. That's how all of my code is set up, and it works fine.

As a rule of thumb, C++ system headers have no prefix; C headers have '.h'.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Mac Elite
Join Date: May 2002
Status: Offline
Reply With Quote
Sep 6, 2002, 09:26 PM
 
Namespaces were introduced into C++ after it began being generally used, although they are a part of the official standard. As a result there are two methods of importing headers from the standard library.

import <iostream> is the standard way, which does not do _any_ namespace declarations, you must do them yourself
import <iostream.h> is the legacy way which automatically adds you to the standard namespace for backwards compatibility

So
Code:
import <iostream> using namespace std;
is equivalent to
Code:
import <iostream.h>
[vash:~] banana% killall killall
Terminated
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:45 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2