??????8??size??length:?????????????
??????????????????????C?????в????????????β????????????????????
????// size()?? length():?????????????
????string stringCount = "chenyufeng";
????cout << "stringSize = " << stringCount.size() << endl;
????cout << "stringLength = " << stringCount.length() << endl;
???????????????????10.
??????9??empty???ж????????????
// empty():?ж????????????
string stringIsEmpty = "";
string stringNotEmpty = "chen";
if (stringIsEmpty.empty())
{
cout << "stringIsEmpty == empty" << endl;
}
else
{
cout << "stringIsEmpty != empty" << endl;
}
if (stringNotEmpty.empty())
{
cout << "stringNotEmpty == empty" << endl;
}
else
{
cout << "stringNotEmpty != empty" << endl;
}
??????10??????????????????
????// ???????stream
????cout << "??????????????"<<endl;
????string stringInput;
????cin >> stringInput;
????cout << "stringInput = " << stringInput << endl;
????????????????????C++????????????????????????????????????????????????????
??????11??max_size:?????????????????
????// max_size:
????string stringMaxSize;
????cout << "stringMaxSize = " << stringMaxSize.max_size() << endl;
?????????????18446744073709551599  ?????????????????????????????????
??????12??[]?? at :??????????
????// []??at() :?????
????string stringAt = "chenyufeng";
????cout << "stringAt[3] = " <<stringAt[3] << endl;
????cout << "stringAt.at(3) = " << stringAt.at(3) << endl;
????stringAt[3] = '6';
????stringAt.at(5) = '9';
????cout << "stringAt = " << stringAt << endl;
????????????????????????в?????????±???д????????????????????????
??????13??compare:??????????????0??1 ??-1??
????// compare()
????string stringCompare = "chenyufeng";
????int aaa = stringCompare.compare("chen"); // > 0
????int bbb = stringCompare.compare("chenyufeng"); // == 0
????int ccc = stringCompare.compare("done"); // < 0
????cout << "aaa = " << aaa << ";bbb = " << bbb << ";ccc = " << ccc << endl;
??????14??substr:????????
????// substr
????string stringSubstr = "chenyufeng";
????// ???????4?????3?????
????cout << "stringSubstr.substr(4??3) = " << stringSubstr.substr(4??3) << endl;
????// ???????4????????????
????cout << "stringSubstr.substr(4) = " <<stringSubstr.substr(4) << endl;
????// ???????
????cout << "stringSubstr.substr() = " <<stringSubstr.substr() << endl;
??????15??find????????????
????// find
????string stringFind = "chenyufeng";
????stringFind.find('n');
????cout << "stringFind.find('n') = " << stringFind.find('n') << endl;
????cout << "stringFind.find_first_of('e') = " << stringFind.find_first_of('e') << endl;
????cout << "stringFind.find_last_of('e') = " << stringFind.find_last_of('e') << endl;
???????find???????????????????γ?????±?index??find_first_of??find_last_of?????????κ????γ???????????index??
????????15??C++?е?????????????????????????????????в????????????????????м???????string??????STL?е???????