+ 1
Find a word in given string
there is a string array and we have to find a word from that string array ..
5 Réponses
+ 6
Let's say you have string array:
string array[] = {...};
To search through the array, we need a specific keyword as the search term:
cin >> specific_key;
Then we can compare the specific search term to all the strings in the array:
for (int i = 0; i < array.length(); i++)
{
if (specific_key == array[i])
{
cout << "Found : " << array[i] << " at index position " << i << endl;
}
}
+ 6
The specific key provided in my example is also a string.
0
int search(string* array, int size) {
for (int i = 0; i < size; i++) {
//compare is a string function that compares the strings, returning 0 if they are equal
if (array[i].compare(word) == 0) return i
}
return -1 //if the word wasnt found, return -1
}
0
but the specific key is not a character it's a string...
0
sa bende c++ üzerinde çalısıyorum tecrübeliysen bana yardımcı olurmusun telefon no :0545 587 29 30