C++ 仅在重载中获取字符串>&燃气轮机;操作员istream:
我上多项式课。我还有一个方法,可以把字符串转换成多项式。 现在我尝试为输入运算符实现此方法:C++ 仅在重载中获取字符串>&燃气轮机;操作员istream:,c++,input,operators,C++,Input,Operators,我上多项式课。我还有一个方法,可以把字符串转换成多项式。 现在我尝试为输入运算符实现此方法: istream& operator>> (istream &is, Poly& pol) { //the string that we use: string str; //the new input override the old: pol.emptyPoly(); //getting a string from us
istream& operator>> (istream &is, Poly& pol)
{
//the string that we use:
string str;
//the new input override the old:
pol.emptyPoly();
//getting a string from user and put it into str:
//?????????????????????
// convert the string to polynomial
pol.sToPol(str);
return is;
}
我需要放什么进去????????要从用户处获取字符串并将其放入str中
那么我什么时候做:
Poly p1;
cin>>p1;
用户将输入字符串,并在我的方法中将其转换为多项式
is >> str;
如果字符串没有空格
std::getline(is, str);
如果字符串中有空格。谢谢,但它不起作用。第一个soulootion给我错误:错误C2678:二进制'>>':未找到接受类型为'std::istream'的左操作数的运算符(或没有可接受的转换)。第二个未在中找到getlinestd@AviadChmelnik那么#include如何?我试图将评论编辑为:“我的错误!!,忘了写include字符串”但是5分钟的编辑结束了。谢谢你,伙计!您在“OOP简介”中保存了我的分数: