#眉標= C++ #副標= C++/CLI全景體驗 #大標= C++/CLI基本型別 #作者=文/Stanley Lippman 譯者/李建忠 -----box----- int ival = 0; Int32 ival2 = 0; -----end----- -----box----- int imaxval = int::MaxValue; int iminval = Int32::MinValue; -----end----- -----box----- String^ bonus = "$ 12,000.79"; -----end----- -----box----- double myBonus = double::Parse( bonus, ns ); -----end----- -----box----- #程式1 using namespace System; using namespace System::Globalization; double bonusString( String^ bonus ) { NumberStyles ns = NumberStyles::AllowLeadingWhite; ns |= NumberStyles::AllowCurrencySymbol; ns |= NumberStyles::AllowThousands; ns |= NumberStyles::AllowDecimalPoint; return double::Parse( bonus, ns ); } -----end----- -----box----- int ival = ( int ) myBonus; -----end----- -----box----- int ival2 = Convert::ToInt32( myBonus ); -----end----- -----box----- Console::Write( "{0} : ", ( 5 ).ToString() ); -----end----- -----box----- Console::WriteLine(( 'a' ).ToString() ); -----end----- -----box----- Console::WriteLine(((wchar_t)'a').ToString() ); -----end----- -----box----- #程式2 public ref class R { public: void foo( System::String^ ); // (1) void foo( std::string ); // (2) void foo( const char* ); // (3) }; void bar( R^ r ) { // 呼叫哪一個foo呢? r->foo( "Pooh" ); } -----end----- -----box----- void foo( std::string ); // (2) void foo( const char* ); // (3) -----end-----