3

i've downloaded a code which implements a BoW (Bag of Words) and i get an error in this line:

float label=atof(entryPath.filename().c_str());

It says: argument of type "const boost::filesystem::path::value_type *" is incompatible with parameter of type "const char *"

I've been searching a little bit and I've seen that there's a problem with the conversion between this kind of string to a char but i couldn't find anything related to a float conversion.

I've also seen the diference between string and c_str and I suppose that the error is in the atof since I think that only can convert the string and not the c_str. Is this the possible error?

In addition I'm new in the boost library and I don't know hot to manage this situation.

Thank you very much and sorry for my english

enric.cornella
  • 150
  • 1
  • 1
  • 8
  • possible duplicate of [boost::filesystem::path and fopen()](http://stackoverflow.com/questions/11352641/boostfilesystempath-and-fopen) – Patashu Jun 18 '13 at 11:06
  • oops, you're right, I did a fast search to see if someone had the same problem and I didn't see that one :S – enric.cornella Jun 18 '13 at 11:27

1 Answers1

5

If you use boost::filesystem why not use boost::lexical_cast? If you work on Windows, then atof will not work with path.c_str(), since value_type is wchar_t.

float label = boost::lexical_cast<float>(entryPath.filename().string());

will work perfectly.

Or you simply can use

float label = atof(entryPath.filename().string().c_str());
ForEveR
  • 55,233
  • 2
  • 119
  • 133