DD.です。
再度質問申し訳ありません。
.NETでの開発で、std::string から System::String への変換はどうすればよいのでしょうか?
それぞれが異なるものであり、暗黙の変換やキャストでの変換はできないものであることはわかりましたが、ググってみても System::String → std::string や System::String → char* への変換は多数でてくるのですが。。。
普通に
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 );
}
で上手くいっているようだが。。。
> System::String^ s1 = gcnew System::String( p );
> System::String^ s2 = gcnew System::String( str.c_str() );
は
String コンストラクタ (SByte*)
http://msdn2.microsoft.com/ja-jp/library/k9s9t975(ja-jp,VS.80).aspx
が
> System::String^ s3 = gcnew System::String( wp );
> System::String^ s4 = gcnew System::String( wstr.c_str() );
は
String コンストラクタ (Char*)
http://msdn2.microsoft.com/ja-jp/library/6y4za026(ja-jp,VS.80).aspx」が呼ばれていますね。
SByte*の方は
> value パラメータは、ASCII エンコードの文字列を表す配列へのポインタを指定する必要があります。
> つまり、文字列は、ANSI コード ページを使ってエンコードされます。
となっているので、普通につかえるわけですな。
というか、代わりのクラスがあるのに無理にstd::stringや
MessageBoxを使う必要性があるのでしょうか?
一応
Microsoft Win32 と Microsoft .NET Framework API との対応
http://www.microsoft.com/japan/msdn/net/general/win32map.asp
# .NET Framework 2.0ではないですが。
早々な回答ありがとうございます。
System::String^ s1 = gcnew System::String( p );
あら^^; ほんとですね。
コンパイルエラーで変換できないよ〜と怒られてしまったのにorz
>というか、代わりのクラスがあるのに無理にstd::stringや
>MessageBoxを使う必要性があるのでしょうか?
前々に使っていたクラスを引っ張ってきて使用したかったもので^^;(console app)
と、いいながらも昔の知識を新しいものに無理やり適合させようとさせてただけか。。。やっぱ新しいもの覚えていかんとだめですね。
Blueさんありがとうございました。<(_ _)>
ツイート | ![]() |