Boost logo

Boost Users :

From: Alain Leblanc (aalebl_at_[hidden])
Date: 2008-03-04 22:18:57


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<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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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