我正在尝试制作类似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) 如果我有std::any一个std::string或一个int,我怎么能投清楚交代包含的类型呢?
std::any有type它,但我不能使用这种类型来施放.
例:
#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)