how to check string start in C++

后端 未结 12 2036
Happy的楠姐
Happy的楠姐 2020-11-29 03:31

Is there any way in C++ to check whether a string starts with a certain string (smaller than the original) ? Just like we can do in Java

bigString.startswi         


        
12条回答
  •  孤独总比滥情好
    2020-11-29 04:15

    I'm surprised no one has posted this method yet:

    #include     
    using namespace std;
    
    bool starts_with(const string& smaller_string, const string& bigger_string) 
    {
        return (smaller_string == bigger_string.substr(0,smaller_string.length()));
    }
    

提交回复
热议问题