将boost :: filesystem :: path转换为char? [英] converting boost::filesystem::path into char?

查看:218
本文介绍了将boost :: filesystem :: path转换为char?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经解决了如何将boost路径传递为所需格式的问题,但是我遇到了一些难题,想办法将path.stem传递给char数组,然后对文件名进行一些检查并采取正确的措施

需要读取文件名并检查the然后操作中的下一个可用数字,我打算使用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();中那样使用path的值类型并修改其余的代码,例如,使用通用的std::copy.

或者,可以在此处找到将wchar_t *转换为char *的示例代码.. >

i have worked out how to pass the boost path the required format, but i am having some issues figuring out hot to pass the path.stem into a char array, and then run some check on the filename and take the right action

need to read the filename and check for the next available number in the and then action, i was intending to use a for loop to get the number into an char array and then compare to this separate counter

how can i feed in the path() character by character into a array - or is there a better way !

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:

Given a bfs::path p, p.c_str() gives you access access to the null-terminated char* array.

const char* c = p.c_str();

Full example:

#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 is not the underlying representation on all systems. On Windows for example, it is wchar_t. For that reason one might need to use the value type of path, as in const boost::filesystem::path::value_type* c = p.c_str(); and modify the rest of the code, and for example use the generic std::copy.

Alternatively, an example code for converting a wchar_t * to a char * can be found here.

这篇关于将boost :: filesystem :: path转换为char?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆