本文主要是介绍C++(20):通过starts_with/ends_with检查字符串,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
C++20提供了starts_with用于检查字符串是否以某个字符串开始,ends_with用于检查是否以某个字符串结束:
#include <iostream>
#include <string>
using namespace std;int main()
{string str = "hello and 88";cout<<str.starts_with("hello")<<endl;cout<<str.starts_with("h")<<endl;cout<<str.starts_with("H")<<endl;cout<<str.ends_with("8")<<endl;cout<<str.ends_with("88")<<endl;cout<<str.ends_with(" 88")<<endl;return 0;
}
运行程序输出:
1
1
0
1
1
1
这篇关于C++(20):通过starts_with/ends_with检查字符串的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!