Does an empty string contain an empty string in C++?

后端 未结 7 1410
渐次进展
渐次进展 2021-01-03 00:53

Just had an interesting argument in the comment to one of my questions. My opponent claims that the statement \"\" does not contain \"\"<

7条回答
  •  無奈伤痛
    2021-01-03 01:30

    C++ agrees with your "opponent":

    #include 
    #include 
    using namespace std;
    
    int main()
    {
        bool contains = string("").find(string("")) != string::npos;
        cout << "\"\" contains \"\": "
            << boolalpha << contains;
    }
    

    Output: "" contains "": true

    Demo

提交回复
热议问题