468,512 Members | 1,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Extracting string from a file using C++

I am new to C++ and I am trying to write a program that extracts specified string from a file and places it in an array to be displayed later on. So far I know how to open the file and things of that nature. I get stuck trying to go through the file picking out the string that I want. Someone please help...Thank You!
Sep 11 '06 #1
2 5581
Banfa
9,056 Expert Mod 8TB
So far I know how to open the file and things of that nature. I get stuck trying to go through the file picking out the string that I want. Someone please help...Thank You!
It's good that you have worked out how to open the file, but we can't help you unless you tell us what method you used to open the file.

There are several methods so I could easily choose the wrong one if I just reply.

Remember the more detail you give the easier it is for us to answer your questions.


basically you need to read the file line by line (I assume it's a text file if it contains string data) and search each line for the desired string.
Sep 11 '06 #2
thank you....well....i used the ifstream to open the file and i am using the
getline() to read a line at a time....then i'm using the string.find() to find the string that i am looking for....I then assign that it to an int and place the value in the string.substr() in order to extract the string that I want....the problem is that it only extracts the first incident of that specific character in that line....it just doesnt go through the lines picking out the strings that I want.....the file is actually an .htm.....and I have to extract all of the URLs from it....i.e. everything that starts with <href=" and ends with a ".....I have to take out everything in between those two fields....i hope this helps...thank you very much
Sep 11 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by lecichy | last post: by
5 posts views Thread by Nazgul | last post: by
2 posts views Thread by Steve | last post: by
4 posts views Thread by dexter48 | last post: by
1 post views Thread by TYR | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.