Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
この記事では、System::Stringとconstchar*の間の変換について説明しています。
私の質問は次のとおりです。この構文(marshal_context)を使用して、System ::Stringからchar*(constの欠落に関する注意)に変換することは可能ですか?
そうでない場合、この問題の推奨される解決策は何ですか?
古いMarshal::StringToHGlobalAnsiを使用する必要がありますか?
コメントには追加の質問もあります。
c_str()Stringsが提供するメソッドである、を使用して、基になるcスタイルの文字列を取得できます。ですconstが、自分の変数にコピーするだけですchar*。
c_str()
const
char*
mallocの場合と同じように、十分な大きさのバッファを割り当ててから、そのバッファに割り当てますstrncpy。これを行うには100の異なる方法がありますが、結局のところ、メモリを予約し、文字列をコピーして、楽しんでください。
malloc
strncpy