Advertisement
Naohiro19

C++/CLI and Standard C++

Apr 19th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1.  
  2. #using <System.dll> //.NETライブラリ
  3. #include <iostream> //標準入出力C++ライブラリ
  4. #include <string>   //標準C++文字列ライブラリ
  5.  
  6.  
  7. using namespace System;
  8. using namespace System::Runtime::InteropServices;
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.  
  14.     String^ text = gcnew String(L"文字列");
  15.     IntPtr mptr = Marshal::StringToHGlobalAnsi(text);
  16.     std::string result = static_cast<const char*>(mptr.ToPointer());
  17.     Marshal::FreeHGlobal(mptr);
  18.     cout << result << endl;
  19.  
  20.  
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement