How to append a char to a std::string?

后端 未结 13 2174
半阙折子戏
半阙折子戏 2020-11-29 15:58

The following fails with the error prog.cpp:5:13: error: invalid conversion from ‘char’ to ‘const char*’

int main()
{
  char d = \'d\';
  std::s         


        
13条回答
  •  感动是毒
    2020-11-29 16:17

    str.append(10u,'d'); //appends character d 10 times
    

    Notice I have written 10u and not 10 for the number of times I'd like to append the character; replace 10 with whatever number.

提交回复
热议问题