How to replace all occurrences of a character in string?

后端 未结 15 1250
别那么骄傲
别那么骄傲 2020-11-22 05:54

What is the effective way to replace all occurrences of a character with another character in std::string?

15条回答
  •  名媛妹妹
    2020-11-22 06:25

    I thought I'd toss in the boost solution as well:

    #include 
    
    // in place
    std::string in_place = "blah#blah";
    boost::replace_all(in_place, "#", "@");
    
    // copy
    const std::string input = "blah#blah";
    std::string output = boost::replace_all_copy(input, "#", "@");
    

提交回复
热议问题