字符串作为函数中的参数
问题描述:
我编写了一个函数来搜索它的参数是否在给定的表retrieveb1.txt中.... optab表有两列,其中参数只能位于第一列。 ..in的aviasm.h文件我写了这个代码....字符串作为函数中的参数
class aviasm
{
public:
aviasm(char *,char *);
~aviasm();
void crsymtab();
bool in1(string);
}
在aviasm.cpp文件我写...
bool aviasm::in1(string s)
{
ifstream in("optab1.txt",ios::in);//opening the optab1.txt
char c;
string x,y;
while((c=in.get())!=EOF)
{
in.putback(c);//putting back the charcter into stream
in>>x;//first field
in>>y;
if(x==s)
return true;
else
return false;
}
}
,但我遇到了几个编译错误.. ..
'bool aviasm::in1(std::string)' : overloaded member function not found in 'aviasm'
'aviasm::in1' : function does not take 1 arguments
'syntax error : identifier 'string'
...任何人都可以帮忙吗?
包括在.h文件中? –
你用分号结束了类的定义吗? – Mahesh
此外,通常只需将只读std :: string对象作为const std :: string&'传递给函数即可。注意'const'和'&'(引用)。 –