superstring question

Write your question here.

this is my code about search substring in a file.

but i need to change it to search superstring, which means s is a superstring of t if only if t is a substring of s. s in a input and t is a word in file.
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
#include<iostream>
#include<string>
#include<fstream>

using namespace std;

	
//void substrings(string, int);
int main(){
	ifstream file;
	string filename;
	char answer;
	string search;
	int minilength;

	int count=0;
	string word;
	
	
	cout<<"Enter the file name: ";
        getline(cin,filename);

        file.open(filename.c_str(), ios::out);

	cout<<"Enter a search word: ";
	cin>>search;
	cout<<"Enter minimum length for matches: ";
	cin>>minilength;
	
	if (file.is_open()){
		while(getline(file, word)) {
			if (word.find(search, 0) != string::npos) {
				if (word.length()>=minilength){
					cout<<word<< endl;
				}
			}	       
		}
			
	}
	else
		cout<<"Could not open file";
	file.close();
	return 0;
}
Last edited on
1
2
3
if ( s.find(t) != std::string::npos ) {
    std::cout << s << "\nis a superstring of\n" << t;
}
Topic archived. No new replies allowed.