Post New Topic  Post A Reply
my profile | register | search | faq | forum home
  next oldest topic   next newest topic
» MacOSX - forked.net   » Compile Problems   » gcc 3.1 problems

UBBFriend: Email this page to someone!    
Author Topic: gcc 3.1 problems
duke123
Junior Member
Member # 534

posted October 19, 2002 07:34 AM      Profile for duke123   Email duke123   Send New Private Message      Edit/Delete Post  Reply With Quote 
Hi there!

I've just received my new PowerMac and I 've run into the following problem with OS X 10.2.

Sample Code:
---------------

#include <string>

int main() {
string test("abc");
cout << test << endl;
}
--------------

This piece of code works when it is compiled with gcc 2.95.4 (g++2 test.cpp -o test)

GCC 3.1: g++ test.cpp -o test gives the following error:

test.cpp: In function `int main()':
test.cpp:4: `string' undeclared (first use this function)
test.cpp:4: (Each undeclared identifier is reported only once for each function
it appears in.)
test.cpp:4: parse error before `(' token
test.cpp:5: `cout' undeclared (first use this function)
test.cpp:5: `test' undeclared (first use this function)
test.cpp:5: `endl' undeclared (first use this function)

I've just started programming in C++ so I don't know a solution. I've installed the Developer CD on a clean 10.2 system.

Thanks in advance

Duke


Posts: 1 | Registered: Oct 2002  |  IP: Logged
Clewin
Junior Member
Member # 552

posted November 14, 2002 01:23 PM      Profile for Clewin     Send New Private Message      Edit/Delete Post  Reply With Quote 
You are supposed to either use std::string, std::cout, etc. or declare your namespace in the newer compiler. It looks like it's required with g++3.

example 1:

#include <string>
#include <iostream>

using namespace std;

int main () {
string test("abc");
cout << test << endl;

return 0;
}

--

example 2:

#include <string>
#include <iostream>

int main () {
std::string test("abc");
std::cout << test << endl;

return 0;
}

here - I googled up a tutorial:
http://www.cplusplus.com/doc/tutorial/tut5-2.html


Posts: 1 | From: Brooklyn Center, Minnesota | Registered: Nov 2002  |  IP: Logged

All times are Pacific Time  

Post New Topic  Post A Reply Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
Hop To:

Contact Us | macosx.forked.net

Powered by Infopop Corporation
Ultimate Bulletin BoardTM 6.1.0.2