将 boost::文件系统::p ath 转换为 char?
converting boost::filesystem::path into char?
我已经弄清楚了如何将提升路径传递到所需的格式,但是我在弄清楚将path.stem传递到char数组中时遇到了一些问题,然后对文件名运行一些检查并采取正确的操作
需要读取文件名并检查 Then 操作中的下一个可用数字,我打算使用 for 循环将数字放入 char 数组中,然后与这个单独的计数器进行比较
我怎样才能将 path(( 逐个字符输入到数组中 - 或者有更好的方法!
int count(boost::filesystem::path input) {
cout << "inputzz : " << input << endl;
char data;
wstring winput;
for (int a = 0; a < 4;){
//boost::filesystem::absolute(input).string();
//cout << input.generic_string() << endl;
(input.generic_string()) >> data;
data << (boost::filesystem::path()input.generic_string());
//a++
};
GCC:
给定一个bfs::path p
,p.c_str()
允许您访问以 null 结尾的char*
数组。
const char* c = p.c_str();
完整示例:
#include<iostream>
#include<boost/filesystem/path.hpp>
int main(){
boost::filesystem::path p("~/.bashrc");
const char* c = p.c_str();
std::cout << c << 'n';
char c2[99];
std::strcpy(c2, p.c_str());
std::cout << c2 << 'n';
}
MSVC:
char
不是所有系统上的基础表示形式。例如,在Windows
上,它是wchar_t
.出于这个原因,可能需要使用路径的值类型,如const boost::filesystem::path::value_type* c = p.c_str();
和修改代码的其余部分,例如使用通用std::copy
。
或者,可以在此处找到将wchar_t *
转换为char *
的示例代码。
相关文章:
- 将无符号char*转换为std::istream*C++
- 为什么这个函数将"const char*"转换为"void* const"而不是"const void*"
- 将函数参数"const char*"转换为"std::string_view"是
- C ++如何在使用"tolower"时将char转换为int
- 有没有办法在C++的赋值中将"char**"转换为"double"?
- JavaCPP 错误:无法将参数"1"的"char*"转换为"Abc*
- 为什么从 char 转换为 std::byte 可能是未定义的行为?
- 如何在虚幻引擎4中将char*转换为TCHAR?
- C++:将模板类型 char 转换为 std::string
- strcmp/char* 转换无法按预期工作
- C++中的SQLite char*转换
- 无法从 const char* 转换为 const char *&
- 在 C++ 中将 char 转换为 int,而无需符号位传播
- 如果必须包含西里尔字符,如何将 char* 转换为 std::string?
- 试图使用strCMP时的char转换错误
- 无法从'const char *'转换为'LPCTSTR'
- 将 std::vector<char> 转换为字符* 会导致字符缺陷
- 使用 static_cast 将 char 转换为 int c++
- 如何在 C++(MFC) 中将 char* 转换为 LPCTSTR
- 无法将const char转换为字符串构造字符串