Now, there is a file named a.txt whose contents is as follows:
I want to store them useing list structure,Code:adddd
dddddddddd
sdf
how to solve it ?
Printable View
Now, there is a file named a.txt whose contents is as follows:
I want to store them useing list structure,Code:adddd
dddddddddd
sdf
how to solve it ?
1) open the file as an ifstream
2) use getline on the ifstream to get a string
3) push a copy of the string onto the list.
To check:Code:ifstream file("path_to_file",ios::in);
list<string> data;
string buffer;
while (getline(file,buffer)) data.push_back(buffer);
file.close();
Code:list<string>::iterator it = data.begin();
while (it != data.end()) {
cout << *it <<endl;
it++;
}