如何在C ++中将字符添加到字符串的末尾

时间:2013-08-25 01:56:46

标签: c++ string

我有一个字符串存储为tempP,因为我没有使用C ++的经验。我想知道如何在字符串中添加一个单词。因此,例如在C#中它将是

tempP = tempP + "addtext";

2 个答案:

答案 0 :(得分:5)

正如您所料:

#include <iostream>
#include <string>

int main()
{
    std::string tempP("temp");
    tempP += "addText";    // the same as tempP = tempP + "addtext";
    std::cout << tempP << std::endl;
    return 0;
}

输出:tempaddText

答案 1 :(得分:3)

std:string temp("something");
temp = temp + "addtext";

现在临时是某种文字。

相关问题