小编use*_*490的帖子

std :: map - C++需要所有声明的类型说明符

我想填补一个std::map,但我得到2个编译器错误,我不知道原因是什么.

std::map<std::string, std::string> dirFull;
dirFull["no"] = "north";
dirFull["so"] = "south";
dirFull["ea"] = "east";
dirFull["we"] = "west";
dirFull["nw"] = "north-west";
dirFull["ne"] = "north-east";
dirFull["sw"] = "south-west";
dirFull["se"] = "south-east";
Run Code Online (Sandbox Code Playgroud)

这些是错误:

error: C++ requires a type specifier for all declarations
       dirFull["no"] = "north";
       ^
error: size of array has non-integer type 'const char[3]'
       dirFull["no"] = "north";
               ^~~~
Run Code Online (Sandbox Code Playgroud)


我也试过这个:

std::map<std::string, std::string> dirFull = { 
    {"no", "north"}, {"so", "south"},
    {"ea", "east"}, {"we", "west"},
    {"ne", "north-east"}, {"nw", "north-west"}, 
    {"se", "south-east"}, {"sw","south-west"} };
Run Code Online (Sandbox Code Playgroud)

这会导致完全不同类型的错误: …

c++ dictionary

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

标签 统计

c++ ×1

dictionary ×1