944,144 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 7011
  • C++ RSS
Sep 27th, 2004
0

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

Expand Post »
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...:-|
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wewe is offline Offline
8 posts
since Aug 2004
Sep 27th, 2004
0

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

Try something like this! Remember to #include <list>

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;
}
}
Reputation Points: 10
Solved Threads: 1
Light Poster
coolmel55 is offline Offline
40 posts
since Sep 2004
Sep 30th, 2004
0

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

thank you!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wewe is offline Offline
8 posts
since Aug 2004
Sep 30th, 2004
0

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

Quote originally posted by wewe ...
thank you!

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

Melinda
Reputation Points: 10
Solved Threads: 1
Light Poster
coolmel55 is offline Offline
40 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Quiz Your self!!!
Next Thread in C++ Forum Timeline: Plz. Help me get my program to work





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC