Bug converting std::tr2::sys::path to std::string?

2.5k views Asked by At

I am using the Visual Studio 2013 TR2 filesystem library. I am seeing a bug when converting a UNC path to a string:

#include "StdAfx.h"
#include <filesystem>
#include <iostream>

//------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
    namespace fs = std::tr2::sys;

    fs::path fsPath = "//server/dir";

    std::string sPath = fsPath;

    std::cout << sPath.c_str() << "\n";
}

This will output "\server\dir", not "\\server\dir".

Is there a fix or a workaround for this? Am I doing something wrong?

1

There are 1 answers

1
Armbie On BEST ANSWER

Well I found a workaround that works for me. If I use

sPath = fsPath.string();

I can now pass that string to the std::ifstream constructor. The path string will be "//server/dir" rather than "\\server\dir".