c++ how to replace a string in an array for another string

前端 未结 3 976
逝去的感伤
逝去的感伤 2021-01-26 06:43

I am trying a short code that uses an array, I basically want to replace the word hate for love when I call my function WordReplace but I keep printing the same thing:

I

3条回答
  •  [愿得一人]
    2021-01-26 07:12

    Just use std::replace:

    std::string x[] = {"I", "don't", "hate", "c++"};
    std::replace( std::begin( x ), std::end( x ), "hate", "love" );
    

    live example

提交回复
热议问题