扫码关注官方订阅号
例如 现在有个字符串s="12 23 34"中间都是空格隔开的 我想把每个值都保存的int数组中 thanks
人生最曼妙的风景,竟是内心的淡定与从容!
const size_t SIZE = 10; int * array = new int[SIZE]; std::istringstream stringStream("12 34 44"); for (size_t i = 0; (i < SIZE) && (stringStream >> array[i]); ++i) {}
希望有帮助
一种比较愚钝的方法,如果是我自己我会采用stringstream来进行转化。
char x[10]; int a[10]; std::string name = "12 3 4 56"; const char * s = name.c_str(); const char * s1 = name.c_str(); int i=0; while(s-s1<name.length() && sscanf(s, "%s", x)){ s += strlen(x)+1; a[i++] = atoi(x); }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
希望有帮助
一种比较愚钝的方法,如果是我自己我会采用stringstream来进行转化。