C++:stack.pop() error: cannot initialize a variable of type ‘char‘ with an rvalue of type ‘void‘
LeetCode 中程序的报错位置如下
for(int i=0; i<sz; i++){char c=s.pop();str.push_back(c);
}
执行结果:
编译出错
Line 14: Char 18: error: cannot initialize a variable of type ‘char’ with an rvalue of type ‘void’ char c=s.pop(); ^ ~~~~~~~1 error generated.
解决方法:
因为pop()
只负责清除栈顶元素,不负责返回,所以返回的是void
。应该先top()
写出栈顶元素的值,再pop()
弹出。
Note:
将 char 字符链接成 string 字符串的方法,使用 push_back 逐个追加字符。
for(int i=0; i<sz; i++){char c=s.top();s.pop();str.push_back(c);
}
C++:stack.pop() error: cannot initialize a variable of type ‘char‘ with an rvalue of type ‘void‘相关推荐
- C++ stack pop()返回值 error: cannot initialize a variable of type ‘int‘ with an rvalue of type ‘void‘
LeetCode一道链表倒置题目 struct ListNode {int val;ListNode *next;ListNode(int x) : val(x), next(NULL) {} };c ...
- QT之error: cannot bind non-const lvalue reference of type ‘CBaowen’ to an rvalue of type ‘CBaowen
问题描述:QT中自己编写了一个结构体变量CBaowen,报文中含有函数重载部分(如下所示), 之后定义一个队列变量 QQueue<CBaowen> queue; 当给队列变量赋值时que ...
- 问题解决:CUDA unkonwn error,changing env variable CUDA_VISIBLE_DEVICES
**Linux 下CUDA环境的bug:**cuda unknown error this may be due to an incorrectly set up environment ,chang ...
- C++之error: cannot bind non-const lvalue reference of type ‘myString’ to an rvalue of type ‘myString
先看代码(不想看代码可以直接看代码后的问题描述) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
- Cannot initialize a variable of type 'Stu *' with an rvalue of type 'void *'
code: 将 Stu* pStu = malloc(sizeof(Stu)); 改为 Stu* pStu = (Stu*)malloc(sizeof(Stu)); code #include < ...
- stack.pop()方法_C.示例中的Stack.Pop()方法
stack.pop()方法 C#Stack.Pop()方法 (C# Stack.Pop() method) Stack.Pop() method is used to remove an object ...
- 【C++---const引用】数组进行指针引用传递给函数error: non-const lvalue reference of type ‘int*‘ to an rvalue
目录 原因 类型转换 手动转换 自动转换 关于临时量 关于常量引用(const的引用) const引用的对象不是不能被修改了吗,这里为什么被修改了? 不是说是const引用吗?为什么又变成了引用所绑定 ...
- 天坑的:Fatal Python error: init_sys_streams: can‘t initialize sys standard streams解决方案
[问题描述] 今天用pycharm新建工程突然提示:编译环境有问题,简单写了两行代码测试一直有问题, 报错如下: Fatal Python error: init_sys_streams: can't ...
- 【无标题】CCS3.3下载程序时出现错误:Unexpected Fatal Error Encountered which may have been caused by a stack over
CCS3.3下载程序时出现以下错误:Unexpected Fatal Error Encountered which may have been caused by a stack overflow, ...
- C++ STL:stack和queue
http://blog.csdn.net/wallwind/article/details/6858634 http://blog.csdn.net/chao_xun/article/details/ ...
最新文章
- 智能交通系统无人机派罚单,人脸成为下一个人牌号,人工智能下谁敢犯规
- go语言学习(二)——Gin 框架简介
- 【LeetCode从零单排】No14.LongestCommonPrefix
- 解密微信小程序Java登录流程(ssm实现具体功能)
- Openlayers下载与加载geoserver的wms服务显示地图
- linux 的 grep 命令 和 ngrep 命令
- tensorflow-gpu_tensorflow GPU环境安装踩坑日记
- 读书笔记 effective c++ Item 41 理解隐式接口和编译期多态
- 爬虫---如何抓取app的思路和方案
- python中confusion matrix_Confusion matrix理解
- 宣传文本html,优秀的宣传语(精选50句)
- 微信小程序用vant自定义tabbar页面并跳转相应页面
- 交互技术前沿学习心得——利用眼动追踪改良广告界面
- Codeforces1527B1
- mmd动作:FREELY_TOMORROW
- mysql查询emoji_mysql怎么搜emoji?
- 操作系统复试问题笔记
- java计算机毕业设计消防应急管理系统源码+lw文档+系统+数据库
- 10款精选的后台管理系统
- vue服务端渲染之nuxtjs
热门文章
- Kafka设计解析(三):Kafka High Availability (下)
- 比Google Map更加清晰的网络地图——RealBird
- 剑指_6从尾到头打印链表(Python)
- android studio文件读写,Android 中的文件读写操作
- python抖音表白软件手机版,我喜欢你 抖音表白程序python版
- js实现kmp算法_数据结构作业之完整KMP算法实现通讯录
- asp.net页面去调用通过SSL加密的webservice报错
- ASP.NET页面生命周期和asp.net应用程序生命周期
- 【Zookeeper系列】Zookeeper命令操作(转)
- 中国网和七牛云达成战略合作,携手打造国际化融媒中心