I have problem in using Visual Studio Code to debug c++11 code on Mac.
Specifically, my codes can be compiled (using g++/clang++) and run without problem. But when I use debug mode in VS code, run my code step by step, it will stuck at some random point. Then it has no reaction when click on step into/step over. The Variable Window on the left side will show a loading circle forever, see below. Also my laptop becomes hot and the fan will run at this time.
I have tried the topological sort code below. Sometimes it stucks at the 1st line right after main function, while sometimes it stucks at somewhere else. Without running step by step, the code can be executed till the end and get correct result.
I have no idea what's going on, so I reinstall it but the problem exists. I attached the task.json config files along with the code I used for testing. Please help me and give suggestions. Thanks in advance!
Below is my tasks.json used to set debug configuration:
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++11",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
Below is my code for topological sort in c++11:
#include <queue>
#include <unordered_map>
#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
vector<int> topoSort(vector<vector<int>>& edgeInfo) {
queue<int> zeroDegree;
// ->(stuck at next line, without reaction when click on step into/over)
unordered_map<int, int> inDegree;
vector<int> answer;
vector<vector<int>> graph(4);
for (auto edge: edgeInfo) {
graph[edge[0]].push_back(edge[1]);
inDegree[edge[1]]++;
}
for (int i=0; i<graph.size(); ++i) {
if (inDegree[i] == 0) {
zeroDegree.push(i);
answer.push_back(i);
}
}
while (!zeroDegree.empty()) {
int curr_vertex = zeroDegree.front();
zeroDegree.pop();
for (auto neighbor: graph[curr_vertex]) {
inDegree[neighbor]--;
if (inDegree[neighbor] == 0) {
zeroDegree.push(neighbor);
answer.push_back(neighbor);
}
}
}
return answer;
}
};
int main() {
// ->(or stuck at next line)
vector<vector<int>> edgeInfo = {{0,1}, {1,2}, {1,3}};
Solution topologicalSort;
vector<int> answer = topologicalSort.topoSort(edgeInfo);
for (auto node: answer) {
cout << node << "-> ";
}
cout << "\n";
return 0;
}