LoginSignup
2
1

More than 5 years have passed since last update.

VC++開発の覚え書き①

Posted at

概要

 「Visual Studio」のCLRコンソールアプリケーションで作成したフォームのコントロールから値を取得し、C言語でよく使うint型やchar型に変換して利用可能にする。

内容

System::String^ -> char型

// テキストボックス「TextBox1」から
// データを取得して「char* str」に格納する

using namespace System::Runtime::InteropServices;

// 中略

    char* str = (char*)Marshal::StringToHGlobalAnsi(textBox1->Text).ToPointer();

char型 -> System::String^

char* cStr = "abcde";
String^ sStr = gcnew String(cStr);

System::String^ -> int型

String^ data = "12345";
int intData = int::Parse(data);

int型 -> System::String^

int source = 12345;
String^ text = source.ToString();

最後に

 C言語でしか開発できないので型を変換するしかなく、そのための覚え書きです。
 もっとスマートなやり方等ご存知の方はご教授いただけると助かります。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1