您的位置:首页 > 编程语言 > C语言/C++

c++ string startwith方法使用

2016-06-04 20:34 435 查看
#include <iostream>

using namespace std;


int main()

{

string s("hello, world");

string head("hello");

string tail("ld");

bool startwith = s.compare(0, head.size(), head) == 0;

cout << boolalpha << startwith << endl;

bool endwith = s.compare(s.size() - tail.size(), tail.size(), tail) == 0;

cout << boolalpha << endwith << endl;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: