- 论坛徽章:
- 0
|
查找子串程序
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string b;
int s=0,a;
ifstream in("e:\\gf.cpp");
while(getline(in,b))
{ a=b.find("type");
if(a>=0)
s=s+1;
}
cout<<s;
return 0;
}
其中,gf.cpp文件的代码
#include<iostream>
#cnclude<cstring>
using namespace std;
class str_type{
char string[80];
public:
str_type(char*str=""){strcpy(string,str);}
str_type operator+(str_type str);
str_type operator+(char *str);
void show_str(){cout<<string;}
};
str_type str_type::operator + (str_type str){
str_type temp;
strcpy(temp.string,string);
strcat(temp.string,str.string);
return temp;
}
我输入一个单词“char”时,查找数为正确的,输入子符串时,结果为错误的!这是什么原因呢,请大家多指教:em03::
[ 本帖最后由 yanglinayp 于 2006-4-27 21:46 编辑 ] |
|