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;
}