Printing a specific part of text file into an output file? VERY confused!

Let's say I have an input file "inputF." In this file we have:

I 2 3 4 5 2
W 3 40 0 3 1 2 3
D 4 59 3 2 9 94 94 220
P 0 0 0 2 1 3 6
Q 3 4 2

U 9 3 2 3
R 9 3 2 1 3 4
W 39 9 0 2 1 1 3
D 3 1 32 3 4 5 91 9
Q 9 2 1

For example...
Now, let's say that I want to print everything that happens after W and before Q in ONLY one case (I would want to print D and P, as in the first case, or just D, as in the second), but I don't necessarily know what's happening in between those letters (I have a defined list of variables to work with, but I have no idea how the actual inputF file will arrange them - they can be in a completely random order). So, basically, I know that I want to print everything that happens between W and Q, but I don't know what's actually between W and Q, or how many lines of text there are between the two letters.

Thanks!
Last edited on
bump!
This are the steps how to do it:

1. Open the file http://www.cplusplus.com/reference/iostream/fstream/
2. Read the file line by line to a string http://www.cplusplus.com/reference/string/string/ until eof() using getline http://www.cplusplus.com/reference/string/getline/
3. Put the line in stringstream http://www.cplusplus.com/reference/iostream/stringstream/
4. Read the stringstream in a vector http://www.cplusplus.com/reference/stl/vector/ (like ss >> part; v.push_back(part);) until eof()
5. push_back that part vector into a line vector
6. Read is done, examine the line vector for W and Q and do whatever you want with the lines inbetween
Topic archived. No new replies allowed.