http://stackoverflow.com/questions/236129/split-a-string-in-c String to int, that is atoi, or sscanf, or stringstream can also be used The above solution is wide Spectral. It is divided into individual solutions.
I feel so free to write a C language version. Although stringstream is easy to write, I don’t use it and the efficiency is relatively low...
const char* s = "1 2 3";
int32_t value = 0;
char* line = NULL, *ptr = NULL;
line = strtok_r(const_cast<char*>(s, " ", &ptr));
while (line) {
if (sscanf(line, "%d", &value) >= 1)
(void)value;//这边就是1,2,3之类的
line = strtok_r(NULL, ",", &ptr);
}
http://stackoverflow.com/questions/236129/split-a-string-in-c
String to int, that is atoi, or sscanf, or stringstream can also be used
The above solution is wide Spectral. It is divided into individual solutions.
I feel so free to write a C language version. Although stringstream is easy to write, I don’t use it and the efficiency is relatively low...
Hope this helps
A relatively stupid method. If it were me, I would use stringstream for conversion.