1)怎样把带空格的字符串分割成没有空格的字符串(c++)
/*****************************************************************
split a string with space into several small strings without space
*****************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
void split(char* str, double* position)
{
char* words[3];
char* temp;
temp = strtok(str, " ");
int i = 0;
while(temp!=NULL)
{
words[i] = temp;
temp = strtok(NULL, " ");
position[i] = atof(words[i]);
i++;
}
}
int main()
{
char lineBuf[] = "11.12 11.13 11.14";
std::cout << "1" << std::endl;
double position[3];
split(lineBuf, position);
std::cout << "1" << std::endl;
for(int i=0; i<3; i++)
{
// std::cout << words[i] << std::endl;
// position[i] = atof(words[i]);
std::cout << position[i] << std::endl;
}
return 0;
}