Hi ancient dragon.


i need to extract specific words from 2 different point (directors and writers in a text file), like delimiters example of the text file below: i want alex proyas to be extracted.

words........ DIRECTOR: alex proyas Writers:......

this case is quite similar to the one above, but....

size_t pos = line.find(',');// looks for the 1st comma shown above

but i want to locate the 1st "DIRECTOR:" word, can director be casted into this?

size_t pos = line.find('director:');// possible?

i was thinking the logic ,

1)reading text file using stream, then when use a loop to find the 1st "director:" word

2)then use SUBSTR to add a few positions and getline (extract all ) using another loop til it reads "
Writer: " then stop reading exit out and print whatever is between
...words....Directors: " extract whatever here" Writers:.... words....

i am a C++ novice, can anyone PLEASE put the above description into c++ code.


my actual problem is here
http://www.programmingforums.org/thread23034.html


words........ DIRECTOR: alex proyas Writers:......

Spamming multiple posts and multiple forums with the same message won't do you any favours
http://www.daniweb.com/forums/thread120406.html#post923157

Create a program with what you know. Don't just post one line snippets and hope someone else will just write the whole thing for you.

You've set out the steps, now try and see if you can do it. If you can get as far as "find directory", then that would be something. Even if you can't, we would adjust the response accordingly.

how about this:


std::string line;
ifstream myfile;

myfile.open(file.c_str());

if (myfile.is_open())
{
while (getline (myfile,line))
{
getline (myfile,line);

size_t pos = line.find("Director:");// locate 1st director word
std::string id = line.substr(pos+1);// get remaining sentence
pos = id.find('W');//remove the rest of the line after reading W
id = id.substr(0,pos);

cout << id ;


myfile.close();

}

}

else cout << "Unable to open file";

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.