获取“boost::文件系统::p ath”字符指针时出现问题
Issue getting `boost::filesystem::path` character pointer
在以下两行中,第一行给了我编译时错误,第二行很好:
std::remove( boost::filesystem::path( mypath / "file.log" ).c_str() );
std::remove( boost::filesystem::path( mypath / "file.log" ).string().c_str() );
std::remove
签名为:int remove( const char* fname );
这是错误消息:
">没有重载函数"std::remove"的实例与参数列表匹配">
但是boost::filesystem::path::c_str()
和std::string::c_str()
都返回了const char*
.
我正在使用的编译器是Visual C++ 2013。
但是 boost::filesystem::p ath::c_str(( 和 std::string::c_str(( 返回常量字符*
不,这不是真的。
我们可以打开boostfilesystempath.hpp
源代码,看看那里发生了什么:
template< typename Char, Char Separator, Char PreferredSeparator, Char Dot >
struct path_constants
{
typedef path_constants< Char, Separator, PreferredSeparator, Dot > path_constants_base;
typedef Char value_type; // <---
//...
};
class path :
public filesystem::path_detail::path_constants<
#ifdef BOOST_WINDOWS_API
wchar_t, L'/', L'', L'.' // [1]
#else
char, '/', '/', '.'
#endif
>
{
在 [1] 行中,wchar_t
作为第一个参数Char
传递给模板path_constants
因此在 Windows c_str
下返回指向宽字符(2 个字节(的指针。
相关文章:
- 指向指向字符数组的指针数组的指针
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 将字符缓冲区强制转换为函数指针
- 在函数中返回无符号字符数组,但不返回指针
- 将字符逐个分配给指针?
- 如何返回实际值(在我的例子中是无符号字符数组)而不是来自 C++ 函数的指针?
- 如何循环访问 cpp 中的函数返回的字符指针数组
- 将字符数组复制到 QByte 数组中,而无需传递指针
- C++:使用没有位移位的指针将无符号字符转换为无符号 int
- C++指针数组到字符数组中的特定位置
- 如何从链表指针字符中查找字符
- 获取字符数组地址,然后转换为指针字符
- 在指针字符 c++ 中分配字符数组的值
- C 指针字符
- 将向量传递<char>到指针字符*
- 如何修复未对齐的指针(字符**)
- 如何打印指针字符数组
- 指针 *字符和 &字符
- C++指针字符
- C/ c++:从指针字符一维数组中访问单个字符