小编inn*_*tic的帖子

如何用Go创建像词典一样的Python?

我正在尝试制作类似python的字典.我试过了:

var chunk = map[string]string{
    "code": "5000",
    "error": err,
}

var payload = map[string]string{
    "type": "response",
    "error": chunk,
}
Run Code Online (Sandbox Code Playgroud)

我也试过了

    var payload = map[string]string{
    "type": "response",
    "error": {
        "code": "5000",
        "error": err,
    },
}
Run Code Online (Sandbox Code Playgroud)

go

3
推荐指数
1
解决办法
153
查看次数

将std :: any转换为未知类型

如果我有std::any一个std::string或一个int,我怎么能投清楚交代包含的类型呢?

std::anytype它,但我不能使用这种类型来施放.

例:

#include <any>
#include <iostream>
#include <string>

int main(void) {
    std::any test = "things";
    std::any test2 = 123;

    // These don't work
    std::string the_value = (std::string) test;
    int the_value2 = (int) test2;

    std::cout << the_value << std::endl;
    std::cout << the_value2 << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ c++17

2
推荐指数
2
解决办法
2762
查看次数

标签 统计

c++ ×1

c++17 ×1

go ×1