string::find
Posted xpylovely
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了string::find相关的知识,希望对你有一定的参考价值。
string (1) |
size_t find (const string& str, size_t pos = 0) const noexcept; |
---|---|
c-string (2) |
size_t find (const char* s, size_t pos = 0) const; |
buffer (3) |
size_t find (const char* s, size_t pos, size_type n) const; |
character (4) |
size_t find (char c, size_t pos = 0) const noexcept; |
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1 = "i love lyy, i hope lyy can be married to me";
string s2 = "lyy";
cout << s1.find(s2) << endl;
cout << s1.find(s2, 50) << endl;
if(s1.find(s2, 50) == string::npos)
cout << "out_of_range" << endl;
const char *s3 = "lyy";
cout << "3: " << s1.find(s3, 8, 3) << endl;
cout << "4: " << s1.find(‘m‘, 6) << endl;
return 0;
}
以上是关于string::find的主要内容,如果未能解决你的问题,请参考以下文章
C++ std::string::find_first_of()函数(在字符串中搜索与其参数中指定的任何字符匹配的第一个字符)
lua: function_demo.lua:144: bad argument #2 to 'find' (string expected, got nil
C++中std::string::find_last_of用法