Loop to keep adding spaces in string?

前端 未结 1 915
被撕碎了的回忆
被撕碎了的回忆 2021-01-24 05:12

I have the following code:

sHexPic = string_to_hex(sPic);
    sHexPic.insert(sHexPic.begin() + 2,\' \');
    sHexPic.insert(2,\" \");

I would l

相关标签:
1条回答
  • 2021-01-24 05:54

    Here's how it would be done in C++, using a string :) (I'm using C libraries cuz I'm more familiar with C)

    #include <stdio.h>
    #include <string>
    
    using namespace std;
    
    int main()
    (
       string X;
       int i;
       int y;
    
       X = 35498700;
       y= X.size();
    
       for(i=2;i<y;i+=2)
       {
          X.insert(i," ");
          y=x.size(); //To update size of x
          i++; //To skip the inserted space
       }
    
       printf("%s",X);
    
       return 0;
    }
    

    Have fun :)

    That would "probably" work. If it didn't then please mention so :)

    0 讨论(0)
提交回复
热议问题