jeudi 20 octobre 2016

Increase efficiency - parse integers from string C++

I have a string

12:56:72

I need to get the 3 numbers 12,56 and 72 individually.

I am doing

int i=0,j=0,k=0,n, p[3]; // p[i] stores each ith value
char x[], b[];
x="12:34:56";
n=strlen(x);
while(i<strlen){
        b[k]=x[i];
        ++i;
        ++k;
        if(x[i==]':'){
            p[j]=int(b);
            ++j;
            ++i;
            k=0;
            char temp[] = b;
            b=new char[];
            delete temp;
            }
        }

Can this be bone in a more efficient way?

Aucun commentaire:

Enregistrer un commentaire