Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to get Visualizer to show up in C++ #233

Open
hoaug-tran opened this issue Oct 20, 2024 · 3 comments
Open

Trying to get Visualizer to show up in C++ #233

hoaug-tran opened this issue Oct 20, 2024 · 3 comments

Comments

@hoaug-tran
Copy link

I tried installing Vscode and installing the Debug Visualizer Extension. However I can't get it to work properly. I tried to get it to print out a sorted array using Quick Sort but it failed. Can someone help me? Thanks

#include <iostream>
#include <vector>
#include <string>

using namespace std;

void Swap(int &a, int &b)
{
    int tmp = a;
    a = b;
    b = tmp;
}

void QuickSort(vector<int> &a, int low, int high)
{
    if (low < high)
    {
        int pivot = a[high];
        int i = low - 1;

        for (int j = low; j < high; j++)
        {
            if (a[j] < pivot)
            {
                i++;
                Swap(a[i], a[j]);
            }
        }

        Swap(a[i + 1], a[high]);
        int pi = i + 1;

        
        cout << "Array after partition with pivot " << pivot << ": ";
        for (int k = 0; k < a.size(); k++)
        {
            cout << a[k] << " ";
        }
        cout << endl;

        QuickSort(a, low, pi - 1);
        QuickSort(a, pi + 1, high);
    }
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    cout << "Array before sorting: ";
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;

    QuickSort(a, 0, n - 1);

    cout << "Array after sorting: ";
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;

    return 0;
}

image

@crispyrooster
Copy link

I'm also having trouble getting the visualizer to actually display in contents of containers in c++.

Documentation says we should create a helper method, that converts the container contents to a json string, and this will be visualizable by debug visualizer, but I haven't had success there either.

demo/main.cpp

std::string myGraphJson = "{"kind":{"graph":true},"
""nodes":[{"id":"1"},{"id":"2"}],"
""edges":[{"from":"1","to":"2"}]}";

I have not had success on visualizing myGraphJson, myGraphJson.c_str(), etc.

If @hediet could help explain what we're doing wrong, that would be very helpful.

@langyuly
Copy link

langyuly commented Feb 3, 2025

I am having the same problem at my side with the cpp demo.

@Klummel69
Copy link

Klummel69 commented Feb 12, 2025

It is probably because the option “-enable-pretty-printing” is not set in gdb.

Has the option been changed in the launch.json file? See example
https://github.com/hediet/vscode-debug-visualizer/blob/master/demos/cpp/.vscode/launch.json

Image

See also C/C++ visualization #119

For an optimal view (e.g. grid), you should create a function that formats the data accordingly, see Visualization Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants