Inspecting STL containers in Visual Studio debugging

前端 未结 10 1377
旧巷少年郎
旧巷少年郎 2020-12-05 06:52

If I have a std::vector or std::map variable, and I want to see the contents, it\'s a big pain to see the nth element while debugging. Is there a p

10条回答
  •  孤城傲影
    2020-12-05 07:29

    In vs 2015, I could not get any of these working
    so, i wrote a bit of code

    1: I had vector of vector of long long elements

    std::vector vs(M_coins + 1);
    for (unsigned long long i = 0; i <= M_coins; i++) {
        std::for_each(memo[i].begin(), memo[i].end(), [i, &vs](long long &n) {
            vs[i].append(std::to_string(n));
            });
    }
    // now vs is ready for use as vs[0], vs[1].. so on, for your debugger
    

    basically what i did was converted vector into string. i had vector of vector so i had string vector to fill.

    2: if you have just a vector of long long elements, then just convert as below:

    std::vector s;
    std::for_each(v1.begin(), v1.end(), [&s](long long &n) {
        s.append(std::to_string(n));
        });
    // now s is ready for use, for your debugger
    

    hope it helped.

提交回复
热议问题