のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

std::stringとSystem::String ^の変換

Blueさんがここに書いてたのがすごく参考になった。
http://hpcgi1.nifty.com/MADIA/Vcbbs/wwwlng.cgi?print+200601/06010037.txt

int main()
{
    const char* p = "abcぜんかく";
    std::string str = "ABC全角";
    const wchar_t* wp = L"abcぜんかく";
    std::wstring wstr = L"ABC全角";

    System::String^ s1 = gcnew System::String( p );
    System::String^ s2 = gcnew System::String( str.c_str() );
    System::String^ s3 = gcnew System::String( wp );
    System::String^ s4 = gcnew System::String( wstr.c_str() );

    System::Console::WriteLine( s1 );
    System::Console::WriteLine( s2 );
    System::Console::WriteLine( s3 );
    System::Console::WriteLine( s4 );
}