利用VS2008中的C++程序编写
技巧说明
1.跳出消息说明为System::Windows::Forms::MessageBox::Show();
2.类的属性声明为 private: static int i=0;必须添加static
3.控件属性为this->label1->Text
4.C++没有null这个标记符
5.对于类型的new一般设置为gcnew
6.线程的定义为private: static System::Threading::Thread^ threadtest;
7.在string类型在C++中是#include <string>和using namespace std;
声明字符串是 std::string这是VC6.0中的定义
8. 利用VS2008中的字符串定义
System::String^ test="hello world!";
System::Windows::Forms::MessageBox::Show(test);
9.数组的定义。
整型数组定义 System::Int32 a[10];
字符串数组定义 array<System::String^>^ StrArray;
array<System::String ^> 是System::String的泛类.其实就是个字符串数组
例子:array<System::String^,2>^ doubleArray=gcnew array<System::String^,2>(2,2);
整型定义 System::Int32 a;
10.Std:string与System::String ^相互转换
std::string ConvertToString(System::String^ str)
{
int q=(int)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str);
char* p=(char*)q;
return std::string(p);
}
主要是为了unicode到ansi的转换
11.
::的含义:
^的含义:类型名称String后面的字符^表示这是引用String类型对象的句柄。
12. array与System:Array是不相同的
13.C#中的new 与VC++中的gcnew