convert Rcpp::CharacterVector to std::string

前端 未结 2 1305
既然无缘
既然无缘 2020-12-14 08:07

I am trying to open a file within an Rcpp function, so I need the file name as a char* or std::string.

So far, I have tried the following:

#include &         


        
相关标签:
2条回答
  • 2020-12-14 08:30

    The real issue is that Rcpp::as requires that you specify the type you want to convert to manually, such as Rcpp::as<std::string>.

    The input of all as overloads is always a SEXP so the compiler does not know which one to use and cannot make the decision automatically. that's why you need to help it. Things work differently for wrap which can use the input type to decide which overload it will use.

    0 讨论(0)
  • 2020-12-14 08:41

    Rcpp::as() expects a SEXP as input, not a Rcpp::CharacterVector. Try passing the f1 parameter directly to Rcpp::as(), eg:

    std::string fname = Rcpp::as(f1); 
    

    Or:

    std::string fname = Rcpp::as<std::string>(f1); 
    
    0 讨论(0)
提交回复
热议问题