Gnu C++ Library Header file question?

This is a discussion on Gnu C++ Library Header file question? within the C++ Programming forums, part of the General Programming Boards category; What header file would I use to take advantage of the linked list functions available? In particular this one. a.join(b) ...

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Question Gnu C++ Library Header file question?

    What header file would I use to take advantage of the linked list functions available?

    In particular this one.
    a.join(b)

    Link to Gnu Library

    It mentions that the classes are located in these files.
    `g++-include/List.hP' and `g++-include/List.ccP'
    Are those header files? I've never seen anything other than .h for a header file.
    Last edited by xviddivxoggmp3; 09-28-2003 at 01:58 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    You probably want to use the stl list. In that case you would #include <list> If you do want to use the gnu list you have to make sure it is installed, perhaps with find in the /usr/include and /usr/local/include Once you find it you should be able to just do #include <List.hP> The include directive really just does a text subsitution of the #include into the file. You can even include .cc files if you need to.

  3. #3
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Question follow up questions

    How would I know if the user has it installed?
    Is it not standard in the compiler?
    How do we find out what header files are installed on a pc?
    What is the stl list?
    Does that mean standard library list?
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  4. #4
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Is it not standard in the compiler?
    Only standard libraries are standards.

    How do we find out what header files are installed on a pc?
    Take a look into the include directories.

    What is the stl list?
    Does that mean standard library list?
    STL stands for Standard Template Library.

  5. #5
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Header files

    I found a header file within my Compiler that showes almost all the list processing functions I would need for my school assignment. Instead of installing Gnu files I figure I might be able to use these. How can I tell if my teacher would have these files available.

    Does any body know if the afxtempl.h is standard issue for compilers?

    It holds the Clist class. I unfortunately do not have the option of checking my teachers computer for the file.

    [Edit]
    How would I find out what list functions are located in the stl list?
    [/Edit]
    Last edited by xviddivxoggmp3; 09-28-2003 at 05:40 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    It's not standard.

    You could try http://www.cppreference.com/
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Question

    Sorry if these questions are remedial and redundant I guess I'm not catching what I should out of the prior answers.

    (1) stl functions are standard in all compilers? (y/n)

    (2) to access the stl list functions I only need to #include<list.h>?
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    1) Yes
    2) #include <list>
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  9. #9
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    If that is what I should use, then what is wrong with my code.
    It doesn't compile. I thought I could use a structure for a list.

    Code:
     
    // linked list
    #include <iostream.h>
    #include <conio.h>
    #include <process.h>
    #include <fstream>
    #include <list>
    
    using namespace std;
    
    const int SIZE=81;
    
    class linklist                       
    {
    	private:
    		struct link                          
    		{
    		short age;
    		short weight;
    		char fname[SIZE];
    		char lname[SIZE];
    		char ssnumber[SIZE];         
    		};
    		int x;
    
    	public:
    		linklist(); 
    		~linklist();
    };
    
    linklist::linklist()
    { 
    		link Data;
    	
    		list<Data> Data1;
    		list<Data> Data2; 
    }
    
    linklist::~linklist()
    {//(******************)
    
    
    }//(******************)
    
    void main()
    {
    
    }
    I get the following error when trying to compile.

    error C2974: 'std::list' : invalid template argument for '_Ty', type expected

    It errors on both list declarations. Is there an error in my syntax?

    [Edit1]
    I just fixed the constructor and it removed the errors.
    Code:
    
    		//link Data;
    	
    		list<link> Data1;
    		list<link> Data2; 
    I eliminated the Data decloration and replaced it with the struct name link.

    (1) Is this a valid list decloration?

    (2) If not what is wrong with it? It compiles, but I haven't been able to write the remainder of the program yet to test it.

    (3) Does this instantiate two identical empty lists called Data1 and Data2?
    [/Edit1]

    [Edit2]
    Why doesn't this work to assign details to the list?
    Code:
     
    linklist::linklist()
    {
    		list<link> Data1;
    		list<link> Data2;
      
    		Data1.fname.push_front("john"); 
    }
    I even tried to replace the field in red with this below and it still doesn't work. What is wrong with it?
    Code:
      
    		Data1.insert(Data1.fname.push_front("john");
    I have also tried this below and it also does not link.
    Code:
     
    		link Node;
    		
    		list<link> Data1;
    		list<link> Data2;		
    		
    		Data1.Node.push_front("john"); 
    error C2228: left of '.push_front' must have class/struct/union type
    error C2039: 'Node' : is not a member of 'std::list<_Ty,_Ax>'
    with
    [
    _Ty=linklist::link,
    _Ax=std::allocator<linklist::link>
    ]
    These errors have completely lost me.
    What do they mean?

    Think I should have started a new thread for these questions?
    [/Edit2]
    Last edited by xviddivxoggmp3; 09-28-2003 at 11:46 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  10. #10
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    To use a list, you have to write the type between the angle brackets like this: list<link>.
    Then, it defines a list of links, so you have to push in it link structures.
    list<link> data defines a list of links, therefore, you cannot use meaningless constructions like data.fname.push_front() because fname is not part of your list class.
    You have to do something like:
    Code:
    list<link> data;
    
    link lnk;
    /* initialize lnk */
    
    data.push_front(lnk);
    I cannot guarantee it will work but it should looks like that.

    However, are you forced to use a list thing? Couldn't you program your own list class;
    1. It would be good for you to learn how it works.
    2. You obviously don't know about templates so there's no way you can use the STL list well.

  11. #11
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    let me get this correctly.

    What it is doing is initializing a list of structures that are empty?

    Does that mean with the below I have at least created the capsule for the remaining data?
    Code:
     
    class linklist                       
    {
    	private:
    		struct link                          
    		{
    		short age;
    		short weight;
    		char fname[SIZE];
    		char lname[SIZE];
    		char ssnumber[SIZE];         
    		};
    		unsigned short x;
    
    	public:
    		linklist(); 
    		~linklist();
    };
    
    linklist::linklist()
    {	
    		link Node;
    		
    		list<link>Data;
    		
    		Data.push_front(Node);
    }
    The reason why I do not write my own class is due to the pointer combinations escape me.

    The book I'm reading states the syntax should read as follows.
    Code:
     
    list<int> L;
    
    L.push_front(1);
    It doesn't provide details on how to get a structure to work in it.
    So the list is a prebuilt template. Is that correct?

    How would I send data into the node for an entire record of structure to have it linked in a list?
    Last edited by xviddivxoggmp3; 09-29-2003 at 02:04 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  12. #12
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    How would I know if the user has it installed?
    I think any gnu c++ library would have the non-standard list routines. From a quick inspection of the library, I think it would be most useful if you were using lisp like routines but for the conventual push_front, push_back best to use the stl.

    Is it not standard in the compiler?
    The c++ standard is not defined by the compiler but by ANSI or ISO. The clib library provides extra features such as hashing, process managerment, obstacks etc. A good referance is
    http://www.gnu.org/manual/glibc-2.2....mono/libc.html

    How do we find out what header files are installed on a pc?
    The exact header file is only going to effect the person compiling the software.

    What is the stl list?
    http://www.cs.brown.edu/people/jak/p...tltut/tut.html

    Does that mean standard library list?
    You can expect all new compilers to have implementation of the stl.

    The reason why I do not write my own class is due to the pointer combinations escape me.
    You should learn to do it by hand at least once. All you have to do is draw the algorithm out on paper, add some labels representing pointers, and then write the code.

    Your probably want to do something like
    Code:
    struct Item {
         int A[100];
    }; 
     
    list<Item*> lst;
    item.push_front(new Item);

  13. #13
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Code:
     
    struct Item {
         int A[100];
    }; 
     
    list<Item*> lst;
    item.push_front(new Item);
    Let me get this right. This creates a new node, and that new node is an individual 100 element integer array, correct?
    And now after it has been created I can input data into it?

    If I wanted to store a full record in one item location or node, from what I've read is that I would need to put it into a temporary buffer to transfer it as a const pointer into the node.

    Is this correct? If so how do you designate the structure member data to accept the new value?
    Last edited by xviddivxoggmp3; 09-29-2003 at 03:46 AM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  14. #14
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Let me get this right. This creates a new node, and that new node is an individual 100 element integer array, correct?
    And now after it has been created I can input data into it?

    If I wanted to store a full record in one item location or node, from what I've read is that I would need to put it into a temporary buffer to transfer it as a const pointer into the node.

    Is this correct? If so how do you designate the structure member data to accept the new value?
    Haven't got back to this one in a while...
    No, you'd have to write a constructor for Item in this case to have meaning full values in it. You could of course allocate memory and then assign data into it. It's kind of design decision to use memory allocation with new or not. Most times people use new to avoid object slicing I think. Here's a fuller version of the code without new.

    Code:
    #include <iostream>
    #include <list>
    
    struct Item {
      int x, y;
    };
    
    int main(void)
    {
      std::list<Item> lst;
    
      Item item;
      item.x = 5;
      item.y = 5;
    
    
      lst.push_back(item);
      item.x = 3;
      item.y = 5;
    
      lst.push_back(item);
     item.x = 3;
      item.y = 5;
    
      lst.push_back(item);
    
      for (std::list<Item>::const_iterator i = lst.begin(); i != lst.end(); ++i) {
        std::cout << i->x << std::endl;
        std::cout << i->y << std::endl;
      }
    
    
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM
  4. header file compile error
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 02-23-2002, 06:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21