C++ (Cpp) input_string Example

Introduction

The c++ (cpp) input_string example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: C++ (Cpp)

Class/type: input_string

Example#1
File: input_path.cppProject: Avin15/ssh-rd

    fs::path input_to_path(input_string const& path)
    {
        cygwin_conv_path_t flags = CCP_POSIX_TO_WIN_W | CCP_RELATIVE;

        ssize_t size = cygwin_conv_path(flags, path.c_str(), NULL, 0);
        
        if (size < 0)
            throw conversion_error("Error converting cygwin path to windows.");

        // TODO: size is in bytes.
        boost::scoped_array<wchar_t> result(new wchar_t[size]);

        if(cygwin_conv_path(flags, path.c_str(), result.get(), size))
            throw conversion_error("Error converting cygwin path to windows.");

        return fs::path(result.get());
    }

Example#2

fs::path input_to_path(input_string const& path)
{
    cygwin_conv_path_t flags = CCP_POSIX_TO_WIN_W | CCP_RELATIVE;

    ssize_t size = cygwin_conv_path(flags, path.c_str(), NULL, 0);

    if (size < 0)
        throw conversion_error("Error converting cygwin path to windows.");

    boost::scoped_array<char> result(new char[size]);
    void* ptr = result.get();

    if(cygwin_conv_path(flags, path.c_str(), ptr, size))
        throw conversion_error("Error converting cygwin path to windows.");

    return fs::path(static_cast<wchar_t*>(ptr));
}