将 boost::文件系统::p ath 转换为 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 pp.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 *的示例代码。

最新更新