Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3029

Compare 2 std::string in c++ virtual studio 2015

$
0
0
Hey, I'm trying to compare a std::string with a string out of an array. Somehow it doesn't work.

The User types in a word in the main method and it gets delivered to my search method as keyword.

in the search function i have my stringarray with words. If my keyword matches with one of the words in the array, the method shall return true; else false.

Code:

bool serach(string keyword){
                bool found = false;
                int index;

        //Archive//
                string words[] = { "msg", "chrome","steam","spotify","discord" };
       

        //-----// Searching for Input //-----//
                for (int i = 0; i < sizeof(words); i++) {

                        if (words[i] == keyword) {

                                cout << "found";
                                getchar();
                                return true;
                        }
                        if (!found == false && i == sizeof(words)) {
                                return false;
                        }
                }


Viewing all articles
Browse latest Browse all 3029

Latest Images

Trending Articles



Latest Images