vc中字符串截取问题?
我获得一个字符串str1="F55,F57,F59,F60,F63,F73,F74,"中间使用逗号隔开的,如何把F55 F57 F59 F60 F63 F73 F74一个一个的提取出来。谢谢!
[解决办法]
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1="F55,F57,F59,F60,F63,F73,F74";
char *p;
p= strtok(str1,",");
while(p)
{
printf("%s\n",p);
p = strtok(NULL, ",");
}
return 0;
}
[解决办法]
int main(){ const char*str="F55,F57,F59,F60,F63,F73,F74,"; char s[8][10]; int i=0,j=0,k=0; for(;i<7;++i) { k=0; while(1) { if(str[j] != ',') { s[i][k]=str[j]; ++k; ++j; } else { s[i][k]=0; ++j; break; } } } for(i=0;i<7;++i) printf("%s\n",s[i]); }