I can't double characters inside string with function

前端 未结 3 552
夕颜
夕颜 2021-01-23 12:18

I am trying to create a simple function that double the characters inside of a string and outputs the new string. Ex. "hello world" would become "hheelloo wwoorrl

3条回答
  •  别那么骄傲
    2021-01-23 13:05

    using namespace std;
    string doubleChar(string str) {
        string newString(str.size() * 2, '\0');
        for(int i =0;i

    The length of result should be set twice of the input. And index should be multiplied by 2.

提交回复
热议问题