调用'fopen'没有匹配功能(no matching function for call to 'fopen')

编程入门 行业动态 更新时间:2024-10-22 21:28:32
调用'fopen'没有匹配功能(no matching function for call to 'fopen')

我想在我的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.

更多推荐

本文发布于:2023-07-28 19:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308163.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   fopen   matching   call   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!