Error, request for member is of non-class type?

1
2
3
4
while(!input.eof()){
 input.get(search, 100, '\n');
if(search.find(keyword) != string::npos){
	cout << search;

Is what I'm mostly worried about. I'm trying to check for a keyword in a file. Then I want to print the line from the file.


For context:
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"#include <iostream>
#include <cctype>
#include <string.h>
#include <stdio.h>
#include <fstream>
#include <string>

using namespace std;

int main(){

int ans;
char keyword[10];
int s;
char search[100];

struct events{
	
	char name[100];
	 char location[100], 
	 description[100], 
	 date[100],
	  attendance[100], 
	  enthusiasm[100];
};

events activity[50];

ofstream indata;
ifstream input;
indata.open("summer-list.txt");
input.open("summer-list.txt");


do{
	
for( s =0; s < 5; s++){
cout << "Enter the event name: ";
cin >> activity[s].name;
cin.ignore(100, '\n');
indata << activity[s].name << " # ";

cout << "Enter the event loaction: ";
cin>> activity[s].location;
cin.ignore(100, '\n');
indata << activity[s].location << " # ";


cout << "Enter the event date: ";
cin>> activity[s].date;
cin.ignore(100, '\n');
indata << activity[s].date << " # ";



cout << "Enter the event attendance: ";
cin>> activity[s].attendance;
cin.ignore(100, '\n');
indata << activity[s].attendance << " # ";



cout << "Enter the event enthusiasm: ";
cin>> activity[s].enthusiasm;
cin.ignore(100, '\n');
indata << activity[s].enthusiasm << " # " << '\n';


cout << "Would you like to enter another event(1) or search for an event with a keyword(2) or print(3)" << endl;
cin >> ans;
cin.ignore(100, '\n');

if (ans == 2 || ans == 3){
break;
}
}

}while(ans == 1);


	if(ans ==2){
		
	cout << "Enter a keyword: " << endl;
	cin >> keyword;
	cin.ignore(100, '\n');

	
//int length = strlen(activity[50].name);

//for(int m=0; m< length; m++){
//	while(strcmp(keyword, activity[m].name )==0)
while(!input.eof()){
 input.get(search, 100, '\n');
if(search.find(string) != string::npos){
	cout << search;

}
}
}
		

	if (ans == 3)	{

	cout<< "Name  #  Location  #  Date  #  Attendance  #  Enthusiasm  " << endl;
	
	for(s =0; s< 5; s++){
	cout << activity[s].name << " # " << activity[s].location << 
     " # " << activity[s].date << " # " << activity[s].attendance << " # " << activity[s].enthusiasm << endl;
}
}

indata.close();
}

The rest is a little messy and my for loop was overriding my do/while until I stuck in a break(not sure why). I'm still tinkering, but if anybody knows why I can't run str.find I'd appreciate some suggestions :)



BTW; I have a teacher that refuses to let us use strings for whatever reason. Most of the functions I need seem to work best with straight strings but she never really gave us the tools to do this a better way so I'm trying to find something that will do the job, regardless of the c(razy) - strings.






Last edited on
but if anybody knows why I can't run str.find

It fails because "search" is not a string, it's a C-string.

I'd appreciate some suggestions


Start using the safer C++ strings instead of the C-strings.

Also please use code tags when posting code.


Topic archived. No new replies allowed.