How to read text file (.txt) into vector of char using STL

Apr 16, 2011 at 2:17pm
I have file text.txt and want to change upper case letters to lower case letters.
I'm not sure how to read from the file and use STL list<char> to store letters.
Apr 16, 2011 at 2:22pm
http://www.cplusplus.com/reference/iostream/ifstream/
Just get() each character from the file and add it to the list. ;)
Apr 19, 2011 at 5:47am
Now I can store characters in <list>.
I want to replace 'ph' with 'f' in words.
For example, the word "photograph" becomes "fotograph".
Can I do this with iterator?
Apr 19, 2011 at 6:23am
Why are you using a vector for this? Why don't you use a string?????
Apr 19, 2011 at 6:39am
My project requires me to use vector. I can't use anything else.
Apr 19, 2011 at 6:50am
closed account (D80DSL3A)
Can I do this with iterator?

Just picture how to do it and then write the code:
1) Use the iterator to search for 'p'.
2) When a 'p' is found check if next element == 'h'
3) If so, overwrite 'p' with 'f' and remove the next element.
Untested, but it seems like that would work.
Apr 19, 2011 at 7:00am
Yeah, but can we access to prev and next pointers of nodes in list?
Apr 19, 2011 at 7:18am
closed account (D80DSL3A)
The iterator for a list is bi-directional so ++iter gives next and --iter gives prev. (hence the term "iterator").
Please read up so you know how to use a list.
http://www.cplusplus.com/reference/stl/list/
Have some code showing an attempt for further help.
Last edited on Apr 19, 2011 at 7:22am
Apr 19, 2011 at 9:51am
Thanks you guys. Finally, I can do it. :D
Topic archived. No new replies allowed.