![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++问题处理
文章平均质量分 50
道纪书生
博士在读,国家奖学金获得者,中国机器人大赛全国亚军,研究方向:CV/SVBRDF Estimation/Object Counting/Swarm Intelligence/Evolutionary Computation,学术or技术交流欢迎私信。
展开
-
C++ 踩坑记录:不能使用sort()函数对unordered_map哈希表进行排序
今天写的以下代码:class Solution {public: static bool cmp(pair<string,int> a, pair<string,int> b){ if (a.second==b.second){ return a.first<b.first; } else return a.second>b.second; } vector<string> topKF.原创 2021-08-25 15:26:35 · 4227 阅读 · 4 评论 -
C++: terminate called after throwing an instance of ‘std::length_error‘ (sort函数cmp排序规则问题)
刷Leetcode-539:最小时间差时遇到了个大问题:报错如下:terminate called after throwing an instance of 'std::length_error' what(): basic_string::_M_create错误代码如下:class Solution {public: static bool cmp(string x,string y){ //手写排序规则 按时间升序排序 int Xshi= (x.原创 2021-08-24 22:52:24 · 22719 阅读 · 9 评论 -
C/C++问题处理:error : no matching function for call to ‘max‘
报错代码: MaxVal=max(MaxVal, words[i].size() * words[j].size() );上面的words 是vector<string>words类型的,即 words[i] 和words[j] 均为字符串。以上代码求之前的MaxVal 值和当前的两个字符串长度的乘积,两者之间的最大值。发生报错:error : no matching function for call to 'max'意思是: 没有用于调用“max”的匹...原创 2021-08-24 16:00:14 · 16248 阅读 · 1 评论 -
C/C++问题处理:(Leetcode) Line 16: Char 21: error: redefinition of ‘j‘ for(int j=0,j<n;j++)
今天刷leetcode 遇到了个小问题:redefinition of 'j' 意思是 j 这个变量重复定义,可往前检查了一遍,并没有定义这个变量。网上的解释都是说:目标头文件.h没有加条件编译语句其实还有一种情况,就是像上面代码里for(int i=0,i<n-1;i++)不小心把 int i=0后面的分号;打成了,这个小地方改一下即可。...原创 2021-08-23 17:46:10 · 941 阅读 · 0 评论 -
C++:没有与参数列表匹配的重载函数 “min“ 实例 (库函数求多个数里的min/max问题)
代码:return min(Count[0],Count[2],Count[3],Count[4],Count[5]);程序报错:使用min/max函数时一般就比较两个数的大小,今天想要求五个数里的最小值,发现程序报错,不能将5个数直接放到min函数当中,而是需要搭配初始化列表来使用,如下所示:return min( { Count[0],Count[2],Count[3],Count[4],Count[5] } );min( {1,2,3,4,5} )注意:在C++11.原创 2021-08-15 15:16:25 · 3105 阅读 · 1 评论 -
C/C++:char型转string型
今天刷Leetcode(Leetcode-1002:查找常用字符)时遇到一个问题:vector<string> result;char ch='a'+i;result.push_back(ch);发现C++无法将char类型数据直接添加进string容器,也就是无法将char型自动转为string型。解决方法如下:vector<string> result;char ch='a'+i;string s(1,ch);result.push_ba...原创 2021-08-14 20:21:30 · 429 阅读 · 0 评论 -
C++ 问题处理:(Leetcode) ==42==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000118
今天刷Leetcode时,代码在本地编译器(VS Code+Gcc)上完美运行,但在Leetcode提交时报错:错误原因是:==42==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000118 意思是堆缓冲区发生了溢出,但仔细检查了代码,好像也没发现啥问题,何况测试用例输入到本地编译器里都能运行,百思不得其解。代码如下:#include<bits/stdc++.h>using name原创 2021-08-04 22:19:22 · 12746 阅读 · 4 评论