我在名为PSM.cpp的文件中有一个cpp代码,如下所示,

#include <Rcpp.h>

// [[Rcpp::export]]
std::vector<std::string> useInitLists() {
    std::vector<std::string> vec = {"larry", "curly", "moe"};
    return vec;
}


当我获取以下代码时,出现以下错误。

> Rcpp::sourceCpp("PSM.cpp")
g++ -m64 -I"C:/PROGRA~1/R/R-30~1.2/include" -DNDEBUG     -I"C:/Users/30708/Documents/R/win-library/3.0/Rcpp/include"  -I"d:/RCompile/CRANpkg/extralibs64/local/include"     -O2 -Wall  -mtune=core2 -c PSM.cpp -o PSM.o
PSM.cpp: In function 'std::vector<std::basic_string<char> > useInitLists()':
PSM.cpp:5:60: error: in C++98 'vec' must be initialized by constructor, not by '{...}'
PSM.cpp:5:60: error: could not convert '{"larry", "curly", "moe"}' from '<brace-enclosed initializer list>' to 'std::vector<std::basic_string<char> >'
make: *** [PSM.o] Error 1
Error in Rcpp::sourceCpp("PSM.cpp") :
  Error 1 occurred building shared library.


有人可以建议错误表示什么以及如何解决吗?谢谢。

最佳答案

您可以使用替代的-std=c++0x,但我从未在Windows上使用过g ++。

(很高兴!)

09-30 10:59