![](/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.