It's a non-class type

Asked 2 years ago, Updated 2 years ago, 22 views

using namespace std;

int main() { char str[80]; char find[10]; char change[10]; char* pstr; char* temp = new char[80]; cin.getline(str, 80); cin.getline(find,10); cin.getline(change,10);

pstr =strstr(str,find);

int index=str.find(find);
int len=strlen(str);
str.replace(index,len,change);

delete []temp;
cout<< str<< endl;
return 0;

} request for member ‘find’ in ‘str’, which is of non-class type ‘char [80]’ It keeps saying int index=str.find(find); I don't know what you mean

c++

2022-09-22 17:57

1 Answers

Error when trying to use char array like an object.

The find function does not call with a char array, but with a string object.

#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string a = "This is C++";
    string b = "C++";

    size_t index = a.find(b);
    cout << index << endl;

    return 0;
}


2022-09-22 17:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.