converting an array of integers to string

后端 未结 5 1720
闹比i
闹比i 2021-01-25 11:23

If I have an array that looks like

int digits[size] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 4}

I want to remove the leading zeros and to d

5条回答
  •  情深已故
    2021-01-25 12:12

    Try the following way:

    int i = 0;
    while(digits[i] == 0) i++;
    for (; i < size; i++)
       result += to_string(digits[i]);
    

提交回复
热议问题