Hi, Could some one point me in the right direction.

I'm trying to get a value thats in a file between tags.
for instance:

I'm reading an array out of a file per line
example:

myArray[0] = "<FILE_NAME>Testfile.dat</FILE_NAME>";

What i'm trying to do is to read every field in the array and search for the value between the predefined tags.

what will be the most efficient way to do this?

Thanks in advanced.
Nick

There are probably several ways to do it, but I would use the string search feature of std::string class

std::string line = "<FILE_NAME>Testfile.dat</FILE_NAME>";
std::string filename;
size_t pos;

if( (pos = line.find("<FILE_NAME>") > string::npos)
{
    filename = line.substr(pos+11);
    // truncate the </FILE_NAME> tag
    pos = filename.find('<'); 
    filename = filename.substr(0, pos);
}
commented: Very Nice +9

For something like this, you would probably have a swell time with Boost.Regex.

thanks for the tips. i'll be testing both then

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.