Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何找到另一个字符串中是否存在一个字符串,而不是使用字符串比较函数,而是通过迭代每个字符并测试 C++ 中的相等性?
string one="hello world"; // Search *in* this string string two="wor"; // Search *for* this string
看起来像家庭作业^^
int find(string one, string two){ int a, b; for(int c = 0; c + two.length() < one.length(); c++){ a = 0; b = c; while(a < two.length() && one[b++] == two[a++]); if(a == two.length())return c; } return -1; }