help on a c++ program


Forum: Other Help Topics
Topic: help on a c++ program
started by: Lii

Posted by Lii on Jan. 03 2005,12:29
Hi,
I'm trying to write a small program that works with a collection of objects in c++ on a rh8.0 box. I got the objects but I can't create the collection.
I reduced the program to the simplest possible code but I'm still getting the same errs.
This is the file a.cpp:

/******start********/
#include <list>

main()
{
  list<int> L;
  return 0;
}

/*****end*******/

and this are the errs:

#gcc a.cpp -o a.cgi
a.cpp: In function `int main()':
a.cpp:5: `list' undeclared (first use this function)
a.cpp:5: (Each undeclared identifier is reported only once for each function it
  appears in.)
a.cpp:5: parse error before `>' token

the file 'list' exists in the include directory.
any ideeas?

Posted by clacker on Jan. 03 2005,17:11
Lii, watch out for the namespace!  Try adding a using namespace std; line and compile it using g++ NOT gcc since it's a c++ program.

Code Sample
#include <list>

using namespace std;

main(){
  list<int> myList;
 myList.push_back (5);
 myList.push_back (6);
 myList.push_front (7);
}


g++ test.cpp -o mytest

Posted by Lii on Jan. 03 2005,20:37
10x a lot! it compiles superbly now :D

I should study more about those namespaces  ???

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.