从c_str()到float的转换
Conversion from c_str() to float
我下载了一个代码,实现了一个BoW (Bag of Words),我在这一行得到一个错误:
float label=atof(entryPath.filename().c_str());
它说:类型"const boost::filesystem::path::value_type *"的参数与类型"const char *"的参数不兼容
我已经搜索了一点,我已经看到有一个问题,这种类型的字符串到字符之间的转换,但我找不到任何相关的浮点转换。
我也看到了string
和c_str
之间的差异,我认为错误是在atof
中,因为我认为只能转换string
而不能转换c_str
。这是可能的错误吗?
另外,我是boost库的新手,我不知道如何处理这种情况。
非常感谢,对不起我的英语
如果你使用boost::filesystem
为什么不使用boost::lexical_cast
?如果你在Windows上工作,那么atof
将不能与path.c_str()
一起工作,因为value_type
是wchar_t
。
float label = boost::lexical_cast<float>(entryPath.filename().string());
可以很好地工作。
或者直接使用
float label = atof(entryPath.filename().string().c_str());
相关文章:
- 没有合适的构造函数可以从"float"转换为"_D3DCOLORVALUE"
- 错误:无法将"float*"转换为"float"
- 有没有一种优雅的方法可以将矢量<复杂<float>>转换为矢量<short>?
- MBED RTOS将Float转换为字符串/字符阵列
- 错误:无法将参数"1"的"float*"转换为"float"
- 有没有快速的方法可以将std::vector<std::vector<float>>转换为std::vector<float2>?
- 将 const float* 转换为 std::array<float, ...>
- 当float转换为int时,此代码中是如何/为什么进行缩小的
- Arduino 无法在初始化时将'float'转换为'const char*'
- C++11自动.从float转换为long
- g++ 在不使用 -Wconvert 的情况下将 double/float 转换为无符号整数时发出警告
- 从 std::vector<std::vector<float>> 转换为 float**
- 在opencv中将垫子转换为矢量<float>和矢量<float>转换为垫子
- 代码一直说:“[错误]无法将参数'1'的'float*'转换为'float'到'void test(flo
- 从'float'转换为'LONG'需要缩小转换范围
- 错误:初始化时无法将'float*'转换为"qreal* {aka double*}"
- Int16_t到float转换的奇怪
- 使用JNI将float*转换为jfloatArray
- 将google::p rotobuf::RepeatedField<float>转换为浮动
- 将float转换为int时的奇怪行为