Help with stringstream

I have a file A that has multiple paragraphs. I need to identify where I matched words from another file B. I need to tell the paragraph, line number, and word number of every where, and identify if it was matched. I've finally gotten so far, having given up on vectors, and ararys, and string splitting. I learned (I think) stringstream :). The problem is, I have the line numbers counting, and the words counting and matching, but I just can't seem to get the paragraph numbers. Could someone please help me? *edit* Each paragraph is separated by "\n" and each sentence is separated by a "." I'll still have to figure out a regex to ignore all other punctuation so that words match 100%.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 #include <iostream>
#include <string>
#include <fstream> // FILE I/O
#include <sstream> // used for splitting strings based upon a delimiting character

using namespace std;

int main() {

	ofstream fout;
	ifstream fin;
	ifstream fmatch;
	string line;
	string word;
	string para;
	string strmatch;
	int p = 0, l = 0, w = 0;
	
	stringstream pbuffer, lbuffer;
	fin.open("text.txt");
	
	while (getline(fin, para)) {
		pbuffer.clear();
		pbuffer.str(".");
		pbuffer << para;
		l++;

		while (pbuffer >> line) {
			
			lbuffer.clear();
			lbuffer.str(" ");
			lbuffer << line;
			

			while (lbuffer >> word) {
				cout << "l " << l << "   W:  " << w << "   " << word;
				fmatch.open("match.txt");
				while (fmatch >> strmatch) {
					if (strmatch.compare(word) == 0) {
						cout << "  Matched!\n";
					}
					else {
						cout << "\n";
					}

				}
				fmatch.close();
				w++;
			}
			
		}
	}


	
	fin.close();
		
	
	
	

	cin.sync();
	cin.get();
}
Last edited on
Topic archived. No new replies allowed.