basename function in filesystem
Hi,
Here's the description of the basename() function in the Filesystem library:
template <class Path> typename Path::string_type basename(const Path & p);
Returns: if p.leaf() contains a dot, returns the substring of
p.leaf() starting at its beginning and ending at the last dot (the dot
is not included). Otherwise, returns p.leaf()
and if I run the following program
==================================================
#include <string>
#include <iostream>
#include
AMDG Alain Leblanc wrote:
Hi,
Here's the description of the basename() function in the Filesystem library:
template <class Path> typename Path::string_type basename(const Path & p);
Returns: if p.leaf() contains a dot, returns the substring of p.leaf() starting at its beginning and ending at the last dot (the dot is not included). Otherwise, returns p.leaf()
and if I run the following program
==================================================
#include <string> #include <iostream>
#include
namespace bf = boost::filesystem; int main() { string name("/calvin/hobbes/xx.xml"); bf::path filepath(name); cerr << "Value for basename: " << basename(filepath.string().c_str()) << endl; } ==================================================
I get as a result:
Value for basename: xx.xml
I seems like I should be getting 'xx'. Am I not understanding the description, or is there a problem with the library.
I'm surprised that that program even compiles. What version of boost are
you using and what compiler. Does this program work better?
#include <string>
#include <iostream>
#include
Well, I figured it out. The file 'string.h' also defines a basename() function. This is why my program was compiling with different argument types. From reading the description I should have noticed I was not using the function provided by boost. Thanks for your help. a On Tue, 2008-03-04 at 18:33 -0800, Steven Watanabe wrote:
AMDG
Alain Leblanc wrote:
Hi,
Here's the description of the basename() function in the Filesystem library:
template <class Path> typename Path::string_type basename(const Path & p);
Returns: if p.leaf() contains a dot, returns the substring of p.leaf() starting at its beginning and ending at the last dot (the dot is not included). Otherwise, returns p.leaf()
and if I run the following program
==================================================
#include <string> #include <iostream>
#include
namespace bf = boost::filesystem; int main() { string name("/calvin/hobbes/xx.xml"); bf::path filepath(name); cerr << "Value for basename: " << basename(filepath.string().c_str()) << endl; } ==================================================
I get as a result:
Value for basename: xx.xml
I seems like I should be getting 'xx'. Am I not understanding the description, or is there a problem with the library.
I'm surprised that that program even compiles. What version of boost are you using and what compiler. Does this program work better?
#include <string> #include <iostream>
#include
namespace bf = boost::filesystem; int main() { std::string name("/calvin/hobbes/xx.xml"); bf::path filepath(name); std::cerr << "Value for basename: " << basename(filepath) << std::endl; }
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Alain Leblanc wrote:
Well, I figured it out. The file 'string.h' also defines a basename() function. This is why my program was compiling with different argument types. From reading the description I should have noticed I was not using the function provided by boost.
I would hope you are not #including string.h you should be including <string> which puts string in namespace std. Jeff Flinn
participants (3)
-
Alain Leblanc
-
Jeff Flinn
-
Steven Watanabe