zoukankan      html  css  js  c++  java
  • 字符串分离函数

    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<
    
  • 相关阅读:
    第03组 Alpha冲刺(3/6)
    第03组 Alpha冲刺(2/6)
    第03组 Alpha冲刺(1/6)
    团队项目-选题报告
    第3组 团队展示
    福大软工 · BETA 版冲刺前准备(团队)
    Alpha 事后诸葛亮
    Alpha冲刺
    Alpha冲刺-(9/10)
    Alpha冲刺
  • 原文地址:https://www.cnblogs.com/trying/p/2863732.html
Copyright © 2011-2022 走看看