[英]how do I store multiple uri values on an array?
我想存储在一个array
中,多个数字通过我的URL的uri传递,例如我有 url:
localhost:8000/234343,43456,7768
如何将数字存储在数组中,如下所示:
array[0]=234343
array[1]=43456
array[2]=7768
如果您知道“,”是分隔符(分隔数字的字符)并且您知道有多少个,则可以使用 string::find():
string array[3];
std::string uri = "localhost:8000/234343,43456,7768";
size_t pos = 0;
std::string delimiter = "/";
pos = uri.find(delimiter);
if (pos == std::string::npos)
throw exception("bad uri");
uri.erase(0, pos + delimiter.length());
delimiter = ",";
std::string token;
while ((pos = uri.find(delimiter)) != std::string::npos && i < 3) {
token = s.substr(0, pos);
array[i] = token;
uri.erase(0, pos + delimiter.length());
i++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.