gpt4 book ai didi

C++验证字符串1是否存在于字符串2中

转载 作者:行者123 更新时间:2023-11-30 03:27:17 24 4
gpt4 key购买 nike

请帮帮我!!

它不起作用,我没有发现错误!?

有一个函数可以验证字符串是否存在?谢谢 !!

#include <iostream>
#include <string>

using namespace std;

int main()
{
string mot1="abc";
string mot2="oooooabcooo";
int j=1;
while((j!=mot1.length())||(j!=0))
{
for(int i=0;i<=mot.length();i++)
{
if(mot1[i]==mot2[i])
{j++;}
else j=0;
}

}
if(j==mot1.length())
cout<<mot1<<" existe dans "<<mot2<<endl;
else

if(j=0)
cout<<"erreur";
return 0;
}

最佳答案

这是您正在寻找的功能。

mot2.find(mot1); // also std::find

希望这对您有所帮助。

关于C++验证字符串1是否存在于字符串2中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47498140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com