我正在尝试.
在 C++ 中拆分一个字符串,然后我需要将第一个拆分的字符串传递给另一个接受的方法const char* key
。但每次我这样做时,我总是会遇到一个异常 -
下面是我的代码 -
istringstream iss(key);
std::vector<std::string> tokens;
std::string token;
while (std::getline(iss, token, '.')) {
if (!token.empty()) {
tokens.push_back(token);
}
}
cout<<"First Splitted String: " <<tokens[0] << endl;
attr_map.upsert(tokens[0]); //this throws an exception
}
下面是 AttributeMap.hh 文件中的 upsert 方法 -
bool upsert(const char* key);
下面是我总是得到的例外 -
no matching function for call to AttributeMap::upsert(std::basic_string<char>&)
有什么我想念的吗?