我试图在点上拆分我的实际密钥,然后在点上拆分后提取所有字段。
我的钥匙看起来像这样 -
t26.example.1136580077.colox
下面是我印象中的代码,它应该可以正常工作,但之后我发现它仅适用于 Windows,我在 ubuntu 上运行我的代码,因此我总是得到 -
error: âstrtok_sâ was not declared in this scope
下面是我的代码
if(key) {
vector<string> res;
char* p;
char* totken = strtok_s(key, ".", &p);
while(totken != NULL)
{
res.push_back(totken);
totken = strtok_s(NULL, ".", &p);
}
string field1 = res[0]; // this should be t26
string field2 = res[1]; // this should be example
uint64_t field3 = atoi(res[2].c_str()); // this should be 1136580077
string field4 = res[3]; // this should be colox
cout<<field1<<" "<<field2<<" "<<field3<<" "<<field4<<endl;
}
我正在运行 Ubuntu 12.04 并且 g++ 版本是 -
g++ (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
有什么方法可以使用普通的 strtok 做同样的事情,因为我不想使用istringstream
strtok 将比 istringstream 更有效。