Mar 20, 2012 at 3:35pm UTC
So I need to find a if a string is subtring of a string. So I found out about this
http://www.cplusplus.com/reference/string/string/find/.
The string I want to search is in a class. And I can't call the string::find? Any solution.
The code is like this:
function.h
1 2 3 4 5 6 7 8 9 10 11
#pragma once
class book
{
char title[200];
....
..
public :
...
...
void find();
};
function.cpp
1 2 3 4 5 6 7 8 9 10 11
#include<iostream>
#include<string>
using namespace std;
#include"function.h"
void book::find()
{
char a[200];
cin.get(a, 200, '\n' );
title.find(a);
}
It's not all the code, but the error is at the title.find(a). The error is:
error C2228: left of '.find' must have class/struct/union
Last edited on Mar 20, 2012 at 3:38pm UTC
Mar 20, 2012 at 3:37pm UTC
If you want to use the string object find function, you need to have an actual string object. You're using arrays of char. An array of char is not a string.
Here is how to make a string:
string a;
Here is how to use the string find function, on the string object:
a.find(title);
Mar 20, 2012 at 3:41pm UTC
You don't use string you use char. char don't have find() function.