【发布时间】:2011-08-11 06:20:23
【问题描述】:
我真的很困惑为什么会出现以下编译错误。 Microsoft Visual Studio 编译器。
error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion)
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iterator>
class MyException {
public:
MyException( std::string message,
int line = 0) : m_message(message),
m_line(line) {}
const char* what() const throw(){
if ( m_line != 0 ) {
std::ostringstream custom_message;
custom_message << "Parsing Error occured at ";
custom_message << m_line << " Line : ";
custom_message << m_message;
m_message = custom_message.str();
}
return m_message.c_str();
}
private:
std::string m_message;
int m_line;
};
int main(int argc, char **argv) {
try {
// do something
}catch(MyException &e){
std::cout << e.what();
}
}
出现错误
m_message = custom_message.str();
【问题讨论】:
-
您缺少标题
<string>,这可能是导致该行为的原因。
标签: c++ visual-studio