相关疑难解决方法(0)

用另一个字符串替换字符串的一部分

在C++中是否可以用另一个字符串替换字符串的一部分?

基本上,我想这样做:

QString string("hello $name");
string.replace("$name", "Somename");
Run Code Online (Sandbox Code Playgroud)

但我想使用标准C++库.

c++ string replace substring std

171
推荐指数
8
解决办法
27万
查看次数

用另一个子串C++替换substring

我怎么能用C++中的另一个子字符串替换字符串中的子字符串,我可以使用哪些函数?

eg: string test = "abc def abc def";
test.replace("abc", "hij").replace("def", "klm"); //replace occurrence of abc and def with other substring
Run Code Online (Sandbox Code Playgroud)

c++ string replace substring

79
推荐指数
8
解决办法
14万
查看次数

寻找 std 算法来替换简单的 for 循环

库中是否有标准算法可以完成以下 for 循环的工作?

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>


int main( )
{
    const char oldFillCharacter { '-' };
    std::vector<char> vec( 10, oldFillCharacter ); // construct with 10 chars
    // modify some of the elements
    vec[1] = 'e';
    vec[7] = 'x';
    vec[9] = '{';

    const char newFillCharacter { '#' };

    for ( auto& elem : vec ) // change the fill character of the container
    {
        if ( elem == oldFillCharacter )
        {
            elem = newFillCharacter;
        }
    } …
Run Code Online (Sandbox Code Playgroud)

c++ for-loop array-algorithms c++20

0
推荐指数
1
解决办法
383
查看次数

标签 统计

c++ ×3

replace ×2

string ×2

substring ×2

array-algorithms ×1

c++20 ×1

for-loop ×1

std ×1