我想在加载包含其路径
的位图时抛出错误ALLEGRO_BITMAP* bitmap;
bitmap_path
if(bitmap=al_load_bitmap(bitmap_path)==0){
throw runtime_error("error loading bitmap from: '"<<bitmap_path<<"'");
};
//continue if no error
答案 0 :(得分:1)
您无法使用<<
运算符直接连接字符串。
如果bitmap_path
是std:::string
,请改用+
运算符:
throw runtime_error("error loading bitmap from: '" + bitmap_path + "'");
如果bitmap_path
是char*
,请将其或第一个字符串文字投放到临时std::string
,以便您可以使用+
:
throw runtime_error("error loading bitmap from: '" + string(bitmap_path) + "'");
throw runtime_error(string("error loading bitmap from: '") + bitmap_path + "'");
否则,您可以使用std::ostringstream
或等效值构建临时std::string
值:
ostringstream oss;
oss << "error loading bitmap from: '" << bitmap_path << "'";
throw runtime_error(oss.str());