我代码中C++的getline()怎么出错了?
时间:2011-12-05
来源:互联网
我的代码如下:
class Infor
{
private:
string name;
string call;
public:
Infor(string str1,string str2)
{
name = str1;
call = str2;
}
~Infor(void){}
void setName(string str1);
void setCall(string str2);
string getName(void)
{
return name;
}
string getCall(void)
{
return call;
}
bool operator == ( Infor &pt) const;
bool operator < ( Infor &pt) const;
friend istream& operator>>(istream& infile,Infor& dt);
friend ostream& operator<<(ostream& outfile,Infor& dt);
};
void Infor::setName(string str1)
{
name = str1;
}
void Infor::setCall(string str2)
{
call = str2;
}
bool Infor::operator == ( Infor &pt) const
{
if(name == pt.getName())
return true;
else
return false;
}
bool Infor::operator < ( Infor &pt) const
{
if(name < pt.getName())
return true;
else
return false;
}
istream& operator>>(istream& infile,Infor& dt)
{
string str1,str2;
infile.getline(str1,30,',');
infile.getline(str2,30,'\n');
dt.setName(str1);
dt.setCall(str2);
return infile;
}
ostream& operator<<(ostream& outfile,Infor& dt)
{
outfile<<dt.getName()<<','<<dt.getCall()<<endl;
return outfile;
}
编译不通过,说
istream& operator>>(istream& infile,Infor& dt)
{
string str1,str2;
infile.getline(str1,30,',');
infile.getline(str2,30,'\n');
dt.setName(str1);
dt.setCall(str2);
return infile;
}
这个错了
class Infor
{
private:
string name;
string call;
public:
Infor(string str1,string str2)
{
name = str1;
call = str2;
}
~Infor(void){}
void setName(string str1);
void setCall(string str2);
string getName(void)
{
return name;
}
string getCall(void)
{
return call;
}
bool operator == ( Infor &pt) const;
bool operator < ( Infor &pt) const;
friend istream& operator>>(istream& infile,Infor& dt);
friend ostream& operator<<(ostream& outfile,Infor& dt);
};
void Infor::setName(string str1)
{
name = str1;
}
void Infor::setCall(string str2)
{
call = str2;
}
bool Infor::operator == ( Infor &pt) const
{
if(name == pt.getName())
return true;
else
return false;
}
bool Infor::operator < ( Infor &pt) const
{
if(name < pt.getName())
return true;
else
return false;
}
istream& operator>>(istream& infile,Infor& dt)
{
string str1,str2;
infile.getline(str1,30,',');
infile.getline(str2,30,'\n');
dt.setName(str1);
dt.setCall(str2);
return infile;
}
ostream& operator<<(ostream& outfile,Infor& dt)
{
outfile<<dt.getName()<<','<<dt.getCall()<<endl;
return outfile;
}
编译不通过,说
istream& operator>>(istream& infile,Infor& dt)
{
string str1,str2;
infile.getline(str1,30,',');
infile.getline(str2,30,'\n');
dt.setName(str1);
dt.setCall(str2);
return infile;
}
这个错了
作者: xihojerry 发布时间: 2011-12-05
好吧。。。已经完结。
把string改成char*就可以了。。。
把string改成char*就可以了。。。
作者: xihojerry 发布时间: 2011-12-05
string str1,str2;----> char str1[30],str2[30];
试试
试试
作者: Demon__Hunter 发布时间: 2011-12-05
这个比较完整的HELP
http://www.cplusplus.com/reference/iostream/istream/getline/
http://www.cplusplus.com/reference/iostream/istream/getline/
作者: keiy 发布时间: 2011-12-05
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28