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

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

9 Years
Discussion Span
Last Post by Salem

Spamming multiple posts and multiple forums with the same message won't do you any favours

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;


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 ;




else cout << "Unable to open file";

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.