954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to read in a sentence and insert in to linked list?

C ++ reading a textfile into linked list

text file:

Humpty Dumpty sat on the wall
Humpty Dumpty had a great fall
all the kings horses and all the kings men
could not put Humpty Dumpty back together again
---------------------------------------------------

the idea is to read in this sentence into a linked list..

i would a ppreciate it if you can post similar codes that read in a sentence..

thanks..

pls help me because my dead line is 2 days away...:-|

wewe
Newbie Poster
8 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 

Try something like this! Remember to #include

void Standard::get_list()
{
char filename[16];
char variable;

cout << "Please enter a filename: ";
cin >> filename;

fstream instream(filename);

if(instream.fail())
{
cout << "Input file opening failed.\n";
exit(1);
}

while (instream >> variable)
list1.push_back (variable);

cout << "\nThe contents of your file: \n" << endl;

for (i=list1.begin(); i != list1.end(); i++)
{
cout << *i << " " << endl;
}
}

coolmel55
Light Poster
40 posts since Sep 2004
Reputation Points: 10
Solved Threads: 1
 

thank you!

wewe
Newbie Poster
8 posts since Aug 2004
Reputation Points: 10
Solved Threads: 0
 
thank you!


Not a problem wanted to know if it worked out for you?

Melinda

coolmel55
Light Poster
40 posts since Sep 2004
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You