如何在字符串中查找两个连续空格的位置

neu*_*cer 3 c++ string

我想检查我的字符串是否有两个连续的空格.找出最简单的方法是什么?

unw*_*ind 6

使用find()方法std::string.std::string::npos如果找不到值,它将返回特殊常量,因此很容易检查:

if (myString.find("  ") != std::string::npos)
{
  cerr << "double spaces found!";
}
Run Code Online (Sandbox Code Playgroud)