| | |
How to read in a sentence and insert in to linked list?
![]() |
•
•
Join Date: Aug 2004
Posts: 8
Reputation:
Solved Threads: 0
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...:-|
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...:-|
•
•
Join Date: Sep 2004
Posts: 40
Reputation:
Solved Threads: 1
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;
}
}
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;
}
}
![]() |
Similar Threads
- how to create linked list? (C)
- Want to learn linked list...please suggest good and detailed articles (C++)
- How to insert data read from text file into linked list? (Java)
- Sort a inputfile to linked list and print it, some problems.. PLZ help :) (C)
Other Threads in the C++ Forum
- Previous Thread: Quiz Your self!!!
- Next Thread: Plz. Help me get my program to work
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes code coding compaitibility compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error factorial file floatingpoint forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple net news node number numbertoword output parameter payment pointer problem program programming project projectassignmenthelp protection python random rank read recursion reference rpg skills string strings temperature template test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets





