代码之家  ›  专栏  ›  技术社区  ›  Brett

在字符串的大写字母后面插入空格

  •  0
  • Brett  · 技术社区  · 5 年前

    我尝试过使用while循环、isupper和.insert((I-1)、“”)。 我注意到,如果它是I+1,它会工作,但是这会给我错误的输出。

    void fixedInput(string &userInput) {
    int i = 1;
    while (userInput[i]) {
        if (isupper(userInput[i])) {
            userInput.insert((i-1)," ");
            tolower(userInput[i]);
        }
        i++;
    }
    }   
    

    对于(i-1),没有输出

    1 回复  |  直到 5 年前
        1
  •  0
  •   Narsarius    5 年前

    看一看 https://stackoverflow.com/a/14494432/11397643

    使用这个概念,你应该能够附加一个空间,以及当做一个转换