Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
 

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: help on a c++ program, can't compile with a 'list' class< Next Oldest | Next Newest >
Lii Offline





Group: Members
Posts: 7
Joined: Nov. 2004
Posted: Jan. 03 2005,12:29 QUOTE

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?
Back to top
Profile PM 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: Jan. 03 2005,17:11 QUOTE

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
Back to top
Profile PM 
Lii Offline





Group: Members
Posts: 7
Joined: Nov. 2004
Posted: Jan. 03 2005,20:37 QUOTE

10x a lot! it compiles superbly now :D

I should study more about those namespaces  ???
Back to top
Profile PM 
2 replies since Jan. 03 2005,12:29 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

 
reply to topic new topic new poll
Quick Reply: help on a c++ program

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code