newb question

This is a discussion on newb question within the C++ Programming forums, part of the General Programming Boards category; Hi, i have a question about inserting structvalues in a list. Code: #include <list> #include <iostream> typedef struct{ int x; ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    30

    newb question

    Hi,

    i have a question about inserting structvalues in a list.

    Code:
    #include <list>
    #include <iostream>
    
    typedef struct{
    int x;
    int y;
    }tfingertips;
    
    using namespace std;
    typedef list<tfingertips> FINGERLIST;
    
    int main ()
    {
    
    FINGERLIST::push_back() = ;
    FINGERLIST::push_back() = ;
    FINGERLIST::push_back() = ;
    
    
    return 1;
    }
    i want to add now values to that list. How can i do it? i have multiple books but they do not describe how to *grmbl*

    Thanks in advance!

    ~Jan

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Try:
    FINGERLIST.push_back(some_struct);

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    148
    Code:
    #include <list>
    #include <iostream>
    
    typedef struct{
    	int x;
    	int y;
    }tfingertips;
    
    using namespace std;
    typedef list<tfingertips> FINGERLIST;
    
    int main()
    {
    	FINGERLIST fingerList;//Create instance
    
    	tfingertips ft = {1,1};
    
    	fingerList.push_back(ft);
    }

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    30
    now i can add stuff, but the reading seems not to work.

    Code:
    #include <list>
    #include <iostream>
    
    typedef struct{
    	int x;
    	int y;
    }tfingertip;
    
    using namespace std;
    typedef list<tfingertip> FINGERLIST;
    
    int main ()
    {
    
    FINGERLIST flist;
    tfingertip tft;
    
    for (int j = 0; j < 20; j++){
    tfingertip tft = {j,j*2};
    flist.push_back(tft);
    };
    
    
    
    for ( int i = 0; i < 5; i++){
    cout << "x: " << tft.x << endl << "y: " << tft.y << endl;
    cout << endl;
    };
    
    return 1;
    }
    its simple but my mind is blocked actually.

    Thanks in advance!

    ~Jan

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    148
    Code:
    	typedef FINGERLIST::const_iterator fiter;
    	for(fiter i = flist.begin();i != flist.end();++i)
    		cout << "x: " << i->x << " y: " << i->y << endl;

  6. #6
    Registered User codegirl's Avatar
    Join Date
    Jun 2003
    Posts
    76
    > i have a question about inserting structvalues in a list.

    Then it would be nice if you'd title the thread something like "Structs and Lists" so that users can find this post in a search later... Not trying to be rude or anything, but I know I like to do searches first so I can avoid redundant posts!

    Sorry I can't help you with the code, I'm not as familiar with the old-style typedef. But Wledge's code looks pretty nifty, I didn't realize you could do that sort of thing!
    My programs don't have bugs, they just develop random features.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question Character Counting
    By Wilder in forum C Programming
    Replies: 13
    Last Post: 06-22-2008, 11:37 PM
  2. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  3. newb question: probs with this program
    By ajguerrero in forum C Programming
    Replies: 5
    Last Post: 04-19-2006, 08:04 AM
  4. Ok. sorry to bother you guys with a newb question.
    By arnis in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2003, 11:23 AM
  5. Win app, newb question
    By Blender in forum Windows Programming
    Replies: 9
    Last Post: 02-04-2003, 11:17 AM

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