C ++ / Rcpp - 更改字符串中的特定字符

时间:2017-08-20 18:26:46

标签: c++ r string replace rcpp

我是C和C ++的新手,所以我在Rstudio中使用Rcpp库,在元音之间将字符'S'更改为'Z'。 我正在尝试使用带有.at函数的迭代器我将其更改为'Z',但该行似乎是错误的。 我知道我做错了什么?

// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/algorithm/string.hpp>

//cc represents the current_character
#define cc   *i

string vowels = "AEIOU";

/* Define .begin .end functions
 */

i = word.begin();
  while(i != word.end()){
    if( cc == 'S' && is(vowels,pc) && is(vowels,nc) ) {

      // the line below seems to e wrong
      word.at(i) == 'Z';

      i += 1;
    } else {
        i += 1;
    }
   }

1 个答案:

答案 0 :(得分:0)

此计划中存在许多潜在错误。

首先,正如@StephanLechner所指出的,你可能并不是指<= p>中的'=='

word.at(i)=='Z';

宏'cc'是非常危险的,至少它需要一个()但更好但不使用它。

循环中有一个潜在的“off by one”错误。

is(vowels,nc)

可能会使用超出单词结尾的那个。

is(vowels,nc)
那是什么?如果nc是另一个宏,它会隐藏真值。