我想用下面这个程序实现子字符串的查找功能,为什么不行呢,大家伙帮我看看问题出在哪。。。
#include
#include
#include
using namespace std;
int findstr(vector vec,string s )
{
int n=0;
for(vector::size_type i=0;i!=vec.size();++i)
if(strcmp(vec[i],s)==0)
n++;
return n;
}
void main()
{
vector vec1;
string s2("you");
string word;
while(cin>>word)
{
vec1.push_back(word);
}
int k=findstr(vec1,s2);
if(k==0)
puts("Not find.");
else
cout<<s2<<" "<<k<<endl;
}
利用vector<string>实现子串的查找
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- 滴水冰冻 2014-02-28 12:22关注
using namespace std;
int findstr(vector vec,char* s )
{
int n =0;
for(vector::iterator iter=vec.begin() ;iter!=vec.end();iter++)
{
if(strcmp(*iter,s)==0)
n++;
}
return n;
}
void main()
{
vector vec1;
char* s2("you");
char word[20][20];
int i=0;
while(cin>>word[i])
{if(0==strcmp("no",word[i])) { break; } vec1.push_back(word[i]); i++;
}
int k=findstr(vec1,s2);
if(k==0)
puts("Not find.");
else
cout<<s2<<" "<<k<<endl;
}
赶紧采纳啊。解决 无用评论 打赏 举报
悬赏问题
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号
- ¥50 安装pyaudiokits失败
- ¥15 计组这些题应该咋做呀
- ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
- ¥15 让node服务器有自动加载文件的功能
- ¥15 jmeter脚本回放有的是对的有的是错的
- ¥15 r语言蛋白组学相关问题
- ¥15 Python时间序列如何拟合疏系数模型
- ¥15 求学软件的前人们指明方向🥺