解决方案
10
假如格式比较固定,不妨考虑sscanf
5
假设char*str=”12,234″,将字符串遍历,找到‘,’将‘,‘赋值成’\0″,则str=“12”,str+3=“234”。
10
#include <iostream>
using namespace std;
int main()
{
char buf[10] = "12,234";
char *p = buf;
int i = 0;
int len = sizeof(buf) / sizeof(*buf);
for (i = 0; i < len; i++)
{
if (p[i] == ",")
{
p[i] == "\0";
break;
}
}
cout << "str1 = " << p << " ";
cout << "str2 = " << p + i + 1;
cin.get();
}
10
用strtok分割成数组,然后分别用atoi/atof转换成数值。
10
题主意思,输入没有格式可言
你就char* p = start,p++碰到连续数字(0-9),记录下来,atoi转换成整数
你就char* p = start,p++碰到连续数字(0-9),记录下来,atoi转换成整数