3

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
Armbie
  • 187
  • 2
  • 12
  • I had actually typed that but the code formatting reduced "\\" to "\". Thanks for the catch. – Armbie Dec 19 '14 at 17:12
  • There was a related bug reported against VS2012, but it's supposed to be fixed: https://connect.microsoft.com/VisualStudio/feedback/details/788976/std-tr2-sys-path-fails-with-unc-paths – Alan Stokes Dec 19 '14 at 17:52
  • I don't see implicit conversion to string in the proposal, this seems like an Visual Studio extension? – Collin Dauphinee Dec 19 '14 at 21:49
  • Visual Studio uses a file_string() method in the header via operator string_type(). Problem seems to be in file_string(). – Armbie Dec 19 '14 at 21:53

1 Answers1

0

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".

Armbie
  • 187
  • 2
  • 12
  • 1
    `string()` returns the path in the native format, meaning directory separators can be either forward or back slashes on Windows. You probably want the generic format, where separators are only forward slashes. – Collin Dauphinee Dec 19 '14 at 21:52