我想在我的cpp函数中调用fopen ,但是, Rcpp总是抱怨“没有匹配函数来调用'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]有人能指出一些暗示吗?
I want to call fopen within my cpp function, however, Rcpp always complains about "no matching function for call to 'fopen'". So duplicated exactly the some code from https://github.com/hadley/xml2/blob/9362d379e126a86091af8698a8987c51b5b230fe/src/xml2_doc.cpp and still have the same error.
#include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] void doc_write(std::string path){ FILE* f = fopen(path.c_str(), 'r'); fclose(f); }and the error is:
testc.cpp:6:36: error: invalid conversion from 'char' to 'const char*' [-fpermissive]Can someone point some hints on me?
最满意答案
错误消息告诉您需要知道的一切 - 您正在尝试传递char参数,其中需要const char * 。 将'r'替换为应该修复它的"r" 。
The error message tells you everything you need to know - you're trying to pass a char parameter where a const char * is required. replace 'r' with "r" that should fix it.
更多推荐
发布评论