This question has been bothering me all day.
if I'm trying to pull out all strings that are in a txt file
and all start with "abcde"
is there anyway to find them, and copy the strings??
assuming the txt file contains lots of text

Look up the methods of the string class. There's a lot you can do with it.

I'm think of using getline()
by using pos=str.find(abcde)
I can locate the str and make a substr till the end of line or specified length
is that gana work? or any other faster way?

one more question
by using my method, can I stop the substr at certain char such as whitespace?

Sounds like your idea will work well. Try it and see.

I don't know about stopping at whitespace, but you can certainly find whitespace after your substring is found.

thanks to WaltP's help
I'm able to figure out a way to solve my problem
here is the structure of my code
hope it will help others

#include<iostream>
#include<fstream>
#include<string>
using namespace std;

int main()
{
string imgURL, line;
size_t pos, found;
ifstream myfile;
myfile.open ("1.txt");
ofstream writefile;
writefile.open ("2.txt");
if(myfile.is_open())
{
  while(myfile.good())
  {
    getline(myfile, line);
    found=line.find("some text");
    if(found!=string::npos)
    {
      pos=line.find("some text");
      imgURL=line.substr(pos);
      //use method like erase or specify a range to copy the string you want
      writefile<<imgURL<<endl;
    }
  }
  myfile.close();
  writefile.close();
}

system("PAUSE");
return 0;      
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.