how to check string start in C++

后端 未结 12 2042
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:16

    To optimize a little bit:

    if ( smallString.size() <= bigString.size() &&
         strncmp( smallString.c_str(), bigString.c_str(), smallString.length() ) == 0 )
    

    Don't forget to #include or #include

提交回复
热议问题