Archived

This topic is now archived and is closed to further replies.

AcidJazz

Linked Lists (using the list class)

Recommended Posts

I''m trying to read a list of names from a file using linked lists, and im using that list class in list.h well im not sure how to read whole names so what i decided to do was make individual lists for individual names then make a list of those names. Sounds like it''d work just fine, but of course due to my programming expertize (or lack of) I can''t manage to do this so would someone like to first explain why this doesnt work and then a better solution? See I do something like this struct NAME // Holds an individual name { list m_Name; }; NAME somename; char letter; while(letter != ''*'') // * indicates end of name in data file { file >> letter; somename.m_Name.insert(m_Name.end(), letter); } /*But for some reason this doesnt work Why the hell not damnit Its like that insert function isnt a part of m_Name, i dont get it. grrrr any other suggestions or explanations?*/

Share this post


Link to post
Share on other sites
/*err sorry for the syntax errors, in the struct its list not just list, i probably fucked up somewhere else too, but i dont think thats the problem.*/

Share this post


Link to post
Share on other sites
I suggest you use "push_back":


  
#include <list>

using namespace std;

// ...


struct NAME // Holds an individual name

{
list<char> m_Name; // I assume you mean this

};

NAME somename;
char letter;

while(letter != ''*'') // * indicates end of name in data file

{
file >> letter;
somename.m_Name.push_back(letter);
}


Dormeur

Share this post


Link to post
Share on other sites