I have the following code:
boost::filesystem::path p = boost::filesystem::current_path();
But I get this error from g++:
filesystem.cc: In function ‘int main(int, char**)’:
filesystem.cc:11: error: no matching function for call to ‘current_path()’
/usr/include/boost/filesystem/operations.hpp:769: note: candidates are: void boost::filesystem::current_path(const boost::filesystem::path&)
/usr/include/boost/filesystem/operations.hpp:771: note: void boost::filesystem::current_path(const boost::filesystem::wpath&)
In /usr/include/boost/filesystem/operations.hpp, I have the following:
template< class Path >
Path current_path()
{
typename Path::external_string_type ph;
system::error_code ec( detail::get_current_path_api( ph ) );
if ( ec )
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::current_path", ec ) );
return Path( Path::traits_type::to_internal( ph ) );
}
So the function is there. I'm using it just like the examples in the boost documentation. Is there something stupid I'm missing here? If I make a path with ".", it works, but I want the full pathname, not just ".".
I have g++ 4.4.6 on RedHat enterprise 6.2, with boost 1.41.0 (I know it's old, but I don't have the option of upgrading).
Looking at the definition of current_path...
template< class Path > Path current_path() ...
current_path is a function template, and the template argument type can't be inferred from its parameters (of which there are none) - so we have to explicitly provide the template argument.current_path() has the same type as the template argument.The reason for this is so we can return narrow and wide character paths ie:
namespace fs = boost::filesystem;
// get the current path
fs::path p = fs::current_path<fs::path>();
// get the current path in wide characters
fs::wpath wp = fs::current_path<fs::wpath>();
wpath is the wide character version of path (akin to wstring and string).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With