char words[5] = { 't', 'd' , 'o', 'g', 'i', };
cout << "enter letter ";
char dogsearch[3] = { 'd', 'o', 'g' };
if (words == dogsearch)
cout << "found words";
else
cout << "Not found word";
i have two arrays and comparing them with each other to find the similiarity, and differences within each another, if there is similiar i want to output how it is, and vice versa
You can use string::find to look for substring matches
char words[5] = { 't', 'd' , 'o', 'g', 'i', };
char dogsearch[3] = { 'd', 'o', 'g' };
string words_str(words, sizeof(words));
string needle(dogsearch, sizeof(dogsearch));
size_t pos = words_str.find(needle);
if (pos != std::string::npos)
cout << "found words at position " << pos << '\n';
else
cout << "Not found word;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.