| | |
How to read in a sentence and insert in to linked list?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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 beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





