how to check string start in C++

后端 未结 12 2002
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:21

    The simplest approach would be:

    if ( smallString.size() <= bigString.size()
        && std::equals( smallString.begin(), smallString.end(), bigString.end() )
    

    (This will also work if one of the two, or both, is a vector. Or any other standard container type.)

提交回复
热议问题