std::string Maker

Utility class for converting System::String to std::string, and more uses.


#pragma once


using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Diagnostics;

class StdStringMaker
private: std::string nativeString;

public: StdStringMaker(System::String^ str)
	    Debug::Assert(str != nullptr); 
	    IntPtr ip = Marshal::StringToHGlobalAnsi(str);
	    this->nativeString = static_cast(ip.ToPointer());

public: operator std::string() const
	    return this->nativeString;

//public: operator CComBSTR() const
//    return this->nativeString.c_str();

public: std::string ToString() const
	    return this->nativeString;