 |
 |
10.2 problems. Can't compile C++
|
 |
|
 |
|
Mac Elite
Join Date: Jul 2002
Status:
Offline
|
|
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
|
|
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.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jul 2002
Status:
Offline
|
|
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
|
|
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
|
|
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
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |