![](/img/trans.png)
[英]Invalid convert from std::sqlString to char const* in C++ and Mysql
[英]C++ - Convert from std::filesystem::path to const char
我有这段代码可以从另一个现有路径创建一个std::filesystem::path
path :
std::filesystem::path outfilename = PathToNewVersionTXT;
是否可以将outfilename
转换为const char*
类型? 因为这是代码后面需要的。
使用path::string()
或path::u8string()
方法将路径获取为std::string
,然后您可以使用string::c_str()
方法:
std::filesystem::path outfilename = PathToNewVersionTXT;
std::string outfilename_str = outfilename.string(); // or outfilename.u8string()
const char *outfilename_ptr = outfilename_str.c_str();
为此使用c_str()
函数。 例如const char* str = path.c_str();
.
看起来您只需要使用std::filesystem::path::c_str
来获取指向w_char_t
(windows) 或char
(Linux) 的指针。
您不能将其更改为const char
因为这只是一个字符,并且您希望多个字符组成一个路径名。 你真的想要一个const char*
这是这个函数返回的(Linux)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.