#define BOOST_FILESYSTEM_VERSION 3 #include #include #include #include #include int main() { // EXAMPLE 1: buffer size known at compile time char buffer1[255] = "./foo"; boost::filesystem::path p1(buffer1); // size() should be 5 (for "./foo") but is actually 254 because // the entire buffer except for the final character was added to // the path! // // The expected behavior would be to stop at the first // NULL-terminator. std::cout << "p1.string().size() is " << p1.string().size() << std::endl; // output: p1.string().size() is 254 // EXAMPLE 2: dynamically allocated buffer char *buffer2 = new char[255]; std::fill(buffer2, buffer2 + 255, '\0'); strcpy(buffer2, "./foo"); // buffer2 is now identical to buffer1 assert(std::equal(buffer1, buffer1 + 255, buffer2)); // ...but boost::filesystem treats it differently. boost::filesystem::path p2(buffer2); std::cout << "p2.string().size() is " << p2.string().size() << std::endl; // output: p1.string().size() is 5 delete [] buffer2; }