我需要使用最少量的代码获取std::string
的第一个字符。从std :: string获取第一个字符
如果能够从STL std::map<std::string, std::string> map_of_strings
中获得一行代码中的第一个字符,那将是非常棒的。在下面的代码正确:
map_of_strings["type"][0]
编辑 目前,我正尝试使用这段代码。这段代码是否正确?
if (!map_of_strings["type"].empty())
ptr->set_type_nomutex(map_of_strings["type"][0]);
的set_type
函数的原型是:
void set_type_nomutex(const char type);
“不起作用”不是问题描述。 – 2012-04-23 19:03:57
你是什么意思“不能正常工作”?发生了什么?你期望会发生什么? – 2012-04-23 19:03:59
你确定原型是正确的吗?如果你使用'type'作为map的键,你应该得到一个编译错误。 – 2012-04-23 19:04:20