Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::filesystem::path and fopen()

I get error when I try to do this:

path p = "somepath";
FILE* file = fopen(p.c_str(), "r");

I get:

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

Could anyone tell me what I'm doing wrong? Thanks

like image 612
Martin Avatar asked Jul 05 '12 21:07

Martin


1 Answers

If you're under Windows, that value_type is wchar_t, and will fail in the conversion for fopen (that needs a char*). As per the documentation, it seems you have to use the string() method to obtain a standard string with a default code conversor (wchar_t -> char):

FILE* file = fopen(p.string().c_str(), "r");
like image 193
Diego Sevilla Avatar answered Oct 18 '22 11:10

Diego Sevilla