http://www.cplusplus.com/reference/clibrary/cstring/strtok/
看一下strtok()函数就会懂了...
另外还有更好用的 istringstream
#include
#include
#include
#include
using namespace std ;
void getValues(const char* source)
{
int value1 ,value2 ;
char* cvalue;
char tmpStr[256] ;
strcpy(tmpStr,source);
cvalue = strtok(tmpStr, ",;");
value1 = atoi(cvalue);
printf("value1: %d\n",value1);
cvalue = strtok(NULL,",;");
value2 = atoi(cvalue);
printf("value2: %d\n",value2);
while( cvalue!=NULL )
{
///使用两个分离符进行分离时会出现先后次序的问题,导致多进行了一次判断
cvalue = strtok(NULL, ",;");
value1 = atoi(cvalue);
printf("value1: %d\n",value1);
cvalue = strtok(NULL,",;");
value2 = atoi(cvalue);
printf("value2: %d\n",value2);
}
}
int main()
{
istringstream istr("-99,26;");
string strTemp;//输出到strTemp中
char c ;
int value ;
int first ;
istr>>first ;
cout<>c ;
cout<>first ;
cout<>c ;
cout<