CoderMti 2022-01-01 15:59 采纳率: 100%
浏览 69
已结题

我编C++的栈时,出现了问题


#include<iostream>
#include<stack>
#include<string>

using namespace std;

stack<int> mystack;
string a;
int n, js = 0;

int main(){
    cin >> n;
    for(int i = 1;i <= n;i ++){
        a = i;
        while(i > 0){
            mystack.push(i % 10);
            i /= 10;
        }
        for(int j = mystack.size() - 1;j > 0;j --){
            if(a[j] == mystack.top()){
                js ++;
                mystack.pop();
            }
        }
        if(js == mystack.size()){
            cout << i << endl;
        }
    }
    return 0;
}

我用Mingw编译的,
运行时出现了这样的错误:
/home/keith/builds/mingw/gcc-9.2.0-mingw32-cross-native/mingw32/libstdc++-v3/include/bits/basic_string.h:1067: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = unsigned int]: Assertion '__pos <= size()' failed.

该怎样改正,谢谢!!

  • 写回答

1条回答 默认 最新

  • CSDN专家-Time 2022-01-01 16:24
    关注

    是不是要配c++11的编译机制。https://www.cnblogs.com/flowingwind/p/8449805.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 1月10日
  • 已采纳回答 1月2日
  • 创建了问题 1月1日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度