CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Feb 2017
    Posts
    3

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

    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;
    			}
    		}
    Last edited by 2kaud; February 23rd, 2017 at 09:46 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured