【解决】VsCode C++异常【terminate called after throwing an instance of ‘char const‘】

大纲

在写栈的相关代码时,使用了 throw  抛异常,但是异常没有抛成功,命令行出现了下面的内容。

问题解决 

原代码为

int main(){
    ArrayStack stack;
    stack.push(1);
    stack.push(4);
    stack.push(6);
    while(!stack.empty()){
        cout << stack.top() << " ";
        stack.pop();
    }
    cout << endl;
    cout<< "size " << stack.size()<

修改后的代码,增加try catch 即问题解决。

int main(){
    ArrayStack stack;
    stack.push(1);
    stack.push(4);
    stack.push(6);
    while(!stack.empty()){
        cout << stack.top() << " ";
        stack.pop();
    }
    cout << endl;
    cout<< "size " << stack.size()<

问题解决正确抛出异常

 

你可能感兴趣的:(c++,开发语言)