【发布时间】:2019-01-11 06:32:36
【问题描述】:
我有一个 std::string 类型的变量。我想检查它是否包含某个 std::string。我该怎么做?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string str;
cin >> n;
string str1 = "not";
while(n--)
{
cin >> str;
cout << "2";
if(str.size() >= str1.size())
{
if (str.find(str1) != string::npos)
{
cout << "1";
}
else
cout << "2";
}
}
return 0;
}
输入:
2
i do not have any fancy quotes
when nothing goes right go left
输出:无输出
【问题讨论】:
-
请研究how to debug small programs - 你的问题与
std::find()无关。 -
无法复制。您声称“没有输出”,但您的代码 does in fact produce output 的
22