• 字符串分离函数


    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<
    
  • 相关阅读:
    近两年目标
    Spring使用ajax异步上传文件
    java注解
    js 点击文本框,预览选择图片
    修改服务器系统时间(包括hive)
    队列原理
    EMR目录
    2个CDH的hive数据同步
    CDH建表字符集问题
    EMR的fair-scheduler.xml
  • 原文地址:https://www.cnblogs.com/trying/p/2863732.html
Copyright © 2020-2023  润新知