我尝试编写一个cpp程序来通过重载 << 运算符来旋转字符串 .
rot.h
class rot
{
public:
std::string const a;
friend std::string operator <<(rot& a, int other);
};
#endif
std::string operator <<(rot& a,const int other);
rot.cpp
std::string& operator<<(rot &os, int const o)
{
return std::rotate(os.a.begin(),os.a.begin()+o,os.a.end());
};
在cpp文件中, std::rotate
带有红色下划线,并带有消息 "initial value of reference to non const must be a lvalue" .
知道如何解决它吗?谢谢!