2 回答

TA貢獻1844條經驗 獲得超8個贊
查找(find)
語法:
size_type find( const basic_string &str, size_type index );
size_type find( const char *str, size_type index );
size_type find( const char *str, size_type index, size_type length );
size_type find( char ch, size_type index );
find()函數:
返回str在字符串中第一次出現的位置(從index開始查找)。如果沒找到則返回string::npos,
返回str在字符串中第一次出現的位置(從index開始查找,長度為length)。如果沒找到就返回string::npos,
返回字符ch在字符串中第一次出現的位置(從index開始查找)。如果沒找到就返回string::npos
例如,
string str1( "Alpha Beta Gamma Delta" );
unsigned int loc = str1.find( "Omega", 0 );
if( loc != string::npos )
cout << "Found Omega at " << loc << endl;
else
cout << "Didn't find Omega" << endl;
添加回答
舉報