gcc 3.1 problems

Find out how to get that @*&^$&@ thing to compile!

gcc 3.1 problems

Postby duke123 » Sat Oct 19, 2002 2:34 pm

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
duke123
 
Posts: 1
Joined: Sat Oct 19, 2002 7:00 pm

Re: gcc 3.1 problems

Postby schnarr » Thu Nov 14, 2002 9:23 pm

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
schnarr
 
Posts: 1
Joined: Thu Nov 14, 2002 8:00 pm
Location: Brooklyn Center, Minnesota


Return to Compile Problems

Who is online

Users browsing this forum: No registered users and 45 guests

cron