How to concatenate a std::string and an int?

前端 未结 23 2629
南方客
南方客 2020-11-22 02:40

I thought this would be really simple but it\'s presenting some difficulties. If I have

std::string name = \"John\";
int age = 21;

How do I

23条回答
  •  野性不改
    2020-11-22 03:33

    As a Qt-related question was closed in favour of this one, here's how to do it using Qt:

    QString string = QString("Some string %1 with an int somewhere").arg(someIntVariable);
    string.append(someOtherIntVariable);
    

    The string variable now has someIntVariable's value in place of %1 and someOtherIntVariable's value at the end.

提交回复
热议问题