1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <string>
#include <sstream>
void mystrsplit(float *array, const std::string input, const char cBegin, const char cEnd);
int main(int argc, char* argv[]){
std::string a="((1.1,1.2)(2.1,2.2)(3.1,3.2))";
float p[3];
float o[3];
mystrsplit(&p[0], a,'(',',');
mystrsplit(&o[0], a,',',')');
for(int ip=0;ip<3;ip++)
{
std::cout<<ip<<": "<<p[ip]<<" : "<<o[ip]<<std::endl;
}
std::cin.get();
return 0;
}
void mystrsplit(float *array, const std::string input, const char cBegin, const char cEnd)
{
std::stringstream sstr;
unsigned int beginNumber=1;
unsigned int endNumber=1;
unsigned int index=0;
while(endNumber!=std::string::npos)
{
beginNumber=input.find(cBegin,beginNumber);
endNumber=input.find(cEnd,beginNumber);
if(endNumber!=std::string::npos)
{
for(unsigned int j=1;j<(endNumber-beginNumber);j++)
{
sstr<<input[beginNumber+j];
}
sstr>>array[index];//=sNumber;
sstr.str(std::string());
sstr.clear();
beginNumber=endNumber;
index++;
}
}
}
|