没有匹配函数来调用 'fopen'
no matching function for call to 'fopen'
我想在我的 cpp 函数中调用 fopen
,但是,Rcpp
总是抱怨 "no matching function for call to 'fopen'"。
所以完全复制了 https://github.com/hadley/xml2/blob/9362d379e126a86091af8698a8987c51b5b230fe/src/xml2_doc.cpp 中的一些代码,但仍然有相同的错误。
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void doc_write(std::string path){
FILE* f = fopen(path.c_str(), 'r');
fclose(f);
}
错误是:
testc.cpp:6:36: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
有人可以给我一些提示吗?
该错误消息告诉您需要知道的一切 - 您正试图在需要 const char *
的地方传递 char
参数。
将 'r'
替换为 "r"
应该可以修复它。
我想在我的 cpp 函数中调用 fopen
,但是,Rcpp
总是抱怨 "no matching function for call to 'fopen'"。
所以完全复制了 https://github.com/hadley/xml2/blob/9362d379e126a86091af8698a8987c51b5b230fe/src/xml2_doc.cpp 中的一些代码,但仍然有相同的错误。
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
void doc_write(std::string path){
FILE* f = fopen(path.c_str(), 'r');
fclose(f);
}
错误是:
testc.cpp:6:36: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
有人可以给我一些提示吗?
该错误消息告诉您需要知道的一切 - 您正试图在需要 const char *
的地方传递 char
参数。
将 'r'
替换为 "r"
应该可以修复它。