Boost logo

Boost Users :

From: PETER BARKER (newbarker_at_[hidden])
Date: 2008-07-16 02:40:35


Hello,
 
I want to use the Boost.Filesystem library in my Win32 application. I've stumbled upon a problem which may very well be my misunderstanding of how to use the library but reading the documentation doesn't clear up my confusion.
 
The user choses a path from a native UI and a bfs::path is constructed with the native name checker. This path needs to be persisted so I call the string() method which according to the documentation "Returns: The contents of m_name, formatted according to the rules of the generic path string grammar." I figured this string would be acceptable to the bfs::path constructor without specifying native because it's in the corrct grammar but I get an exception thrown. Here's a stripped down version of my code:
 
#include <iostream>
#include <iterator>
#include <boost/filesystem/operations.hpp>
namespace bfs = boost::filesystem;
int main()
{
 try
 {
  // Path constructed from a native UI so constructed with native
  bfs::path myPath("C:/autoexec.bat",bfs::native);
  // Persist to grammar conformant string
  std::string persisted = myPath.string();
  // Recreate from persisted string - *THROWS EXCEPTION*
  bfs::path otherPath(persisted);
 }
 catch(const std::exception& e)
 {
  std::cout << e.what() << std::endl;
 }
 return 0;
}
 
The exception string is "boost::filesystem::path: invalid name "C:" in path: "C:/autoexec.bat""
 
Can someone explain how I should be doing this please?
 
Thanks,
 
Pete



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