Boost logo

Boost Users :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-03-04 21:33:20


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<boost/filesystem/operations.hpp>
> 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<boost/filesystem/convenience.hpp>
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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net