首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

错误有关问题

2012-04-04 
异常问题C/C++ code#include iostream#include string#include exceptionusing namespace stdint m

异常问题

C/C++ code
#include <iostream>  #include <string>#include <exception>using namespace std;int main(){    try    {        if(1)            throw "throw";    }catch(string str)//为什么不能把这样传值有问题//改成thrrow string("throw")或者catch(const char* str)就可以呢?    {        cout<<str<<endl;    }    return 0;}


、、望前辈们指点一下。

[解决办法]
本来你抛出的类型就是char*类型

[解决办法]
你抛出什么,他就会catch到什么
[解决办法]
抛出的类型要和catch的类型一致。
[解决办法]
string != const char *
string.c_str() == const char *

热点排行