Getline word by word

Here is my problem:
I have a .txt file, that contains only words. I need to write them into the second file in alphabetic order.
I have to use 26 stacks (one of the rules of task). I have an array of 26 pointers (something like Stack * abc[25]. I have to read from the incoming file first word as a string, but i don't know how to do it... I think i should alter the getline, but i don't know how. Could someone please help?
Take a look at std::string and file i/o.

http://cplusplus.com/reference/string/string/
http://cplusplus.com/reference/string/getline/
http://cplusplus.com/reference/string/operator%3E%3E/

http://cplusplus.com/doc/tutorial/files/

Also, a classmate of yours asked the same question a while ago. You might find the answers we gave him useful too.

http://cplusplus.com/forum/beginner/25002/
Still can not get it. Why does



fstream fin ("mail.txt", ios::in);
string s;
istream& getline (istream& fin, string& s, char ' ');
getline (fin, s);

not work?
1
2
3
4
fstream fin ("mail.txt", ios::in);
string s;
istream& getline (istream& fin, string& s, char ' ');//????????
getline (fin, s);


Should be:

1
2
3
4
fstream fin ("mail.txt", ios::in);
string s;
//istream& getline (istream& fin, string& s, char ' ');
getline (fin, s, ' ' ); 



Doesn't the simpler method below work (or is it a part of the excercise that you use the getline function?

1
2
3
fstream fin ("mail.txt", ios::in);
string s;
fin >> s; 
Last edited on
I mean wow
come on
I waited 3 days for some one to write this

1
2
3
fstream fin ("mail.txt", ios::in);
string s;
fin >> s;


THANK YOU VERY MUCH
Last edited on
I waited 3 days for some one to write this


10 minutes after your original post you were directed by m4ster r0shi to this page:

http://cplusplus.com/reference/string/operator%3E%3E/

Which contained virtually the same answer in the example at the bottom.
Last edited on
Topic archived. No new replies allowed.