【debug】vscode配置c/c++环境及查看调试信息m1 mac

之前用的一直是clion 但是经过反复调整,发现始终查看不了vector里面的数值(只有指针地址),改用常用的vscode后调试成功

  • 安装
  1. 安装vscode 以及vscode中的扩展安装
    c/c++,c/c++ extension pack,cmake,cmake tools,code runner,codeLLDB
  2. 打开一个cpp文件,点击运行旁边的小箭头,选择run code,出现调试配置,选择g+±13生成活动文件,会生成tasks.json
  3. 点击调试,选择debug(lldb),会生成launch.json
  4. 扩展中找到code runner点击设置,找到run in terminal,在whether to run code in integrated terminal前打勾,(从而解决cpp运行和调试中无法在终端进行输入的问题)
  • 运行测试

    打开一个cpp文件,点击运行旁边的小箭头,选择run code

  • debug调试测试

    带vector的测试代码如下:

cpp 复制代码
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
bool cmp(pair<int,double> a,pair<int,double> b){
 return a.first>b.first;
}
int main(){
 map<int,double> poly;
 map<int,double> ans_poly;
 int m,n,ex;
 double co;

  cin>>n;
  for(int i=0;i<n;i++){
   cin>>ex>>co;
   poly[ex]=co;
  }
 cin>>m;
 for(int i=0;i<m;i++){
   cin>>ex>>co;
  
   for(auto p=poly.begin();p!=poly.end();p++ ){
    int new_ex=(*p).first+ex;
    ans_poly[new_ex]+=((*p).second*co);
    //cout<<(*p).second<<" "<<co<<" "<<(*p).second*co<<endl;
   }
 }
  

 vector<pair<int,double> > ans(ans_poly.begin(),ans_poly.end());
 sort(ans.begin(),ans.end(),cmp);
 int cnt=0;
 for(auto it=ans.begin();it!=ans.end();it++){
  if((*it).second)
   cnt++;
 }
 cout<<cnt;
  for(auto it=ans.begin();it!=ans.end();it++){
   if((*it).second)
    printf(" %d %.1lf",(*it).first,(*it).second);
  
 }
 return 0;
}
cpp 复制代码
输入:
2 1 2.4 0 3.2
2 2 1.5 1 0.5

输出:(自行验证是否正确)
3 3 3.6 2 6.0 1 1.6

点击运行和调试,选择debug,在第41行前打红色断点,点击绿色箭头开始调试,

同样的在终端输入上述的输入参数,

可以看到vector中的值了

相关推荐
Forget the Dream27 分钟前
设计模式之责任链模式
java·c++·设计模式·责任链模式
停止重构28 分钟前
【开源】低代码 C++程序框架,Linux多线程程序
c++·低代码·多线程·开源框架·云计算引擎
Duramentee31 分钟前
C++ 设计模式 十二:责任链模式 (读书 现代c++设计模式)
c++·设计模式·责任链模式
_GR36 分钟前
Qt开发⑧Qt的窗口_下_浮动窗口+对话框
开发语言·css·c++·qt·microsoft
萌の鱼1 小时前
leetcode 3183. 达到总和的方法数量
数据结构·c++·算法·leetcode
Forget the Dream1 小时前
设计模式之代理模式
java·c++·设计模式·代理模式
攻城狮7号4 小时前
【第十节】C++设计模式(结构型模式)-Flyweight( 享元)模式
c++·设计模式·享元模式
Forget the Dream4 小时前
设计模式之享元模式
java·c++·设计模式·享元模式
USER_A0018 小时前
【C语言】第八期——指针、二维数组与字符串
c语言
溟洵8 小时前
【C/C++】理解C++内存与Linux虚拟地址空间的关系---带你通透C++中所有数据
linux·c语言·c++