converting an array of integers to string

后端 未结 5 1686
闹比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:14

    Instead of changing digits with your for loop, add them with

     number += to_string(digits[i]);
    

    Also, you can remove the toString line you have, and just use it as I put here.

    As to your other question, just use a for loop to check each digit in the string and its ASCII value, if there is any whose ASCII value is less than 48 or greater than 57 then it's not a number.

提交回复
热议问题