int main()
{
std::stringstream s1("This is my string.");
std::stringstream s2 = s1; // error, copying not allowed
}
Run Code Online (Sandbox Code Playgroud)
我找不到为什么我不能复制stringstream的原因.你能提供一些参考吗?
在创建一个简单的异常类扩展(我可以更容易地构造错误消息)时,我将错误分解为以下简单代码:
#include <sstream>
#include <string>
class myCout {
public:
std::stringstream ssOut; // Removing this gets rid of error
template <typename T> myCout& operator << (const T &x) {
// Do some formatting
return *this;
}
};
class myErr : public myCout {
public:
using myCout::operator<<;
};
int main(int argc, const char* argv[]) {
throw myErr() << "ErrorMsg" << 1;
myCout() << "Message Will Be Formatted";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在编译时,会产生以下错误:
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sstream(724): error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot …Run Code Online (Sandbox Code Playgroud)