日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

Windows 8 C++/CX字符串

發布時間:2023/12/18 c/c++ 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows 8 C++/CX字符串 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

???? 在C++/CX里面是使用Platform::String類來表示字符串的類型,在windows運行時的接口和方法中,需要使用Platform::String來作為字符串參數的傳遞。如果需要使用標準C++的字符串類型如wstring或者string的時候,可以將Platform::String與標準的C++的字符串進行互相的轉換。

?

String類型的構造

String類型表示的是char16的字符串,可以直接通過字符串的賦值來進行構造也可以使用標準C++的wchar_t*指針進行構造。

// Initializing a String^ by using string literalsString^ str1 = "Test"; // ok for ANSI text. uses current code pageString^ str2("Test");String^ str3 = L"Test";String^ str4(L"Test");//Initialize a String^ by using another String^ String^ str6(str1);auto str7 = str2;// Initialize a String from wchar_t* and wstringwchar_t msg[] = L"Test";String^ str8 = ref new String(msg);std::wstring wstr1(L"Test");String^ str9 = ref new String(wstr1.c_str());String^ str10 = ref new String(wstr1.c_str(), wstr1.length());

?

字符的操作

?String提供了相關的方法來操作字符串,其中可以使用String::Data()方法來返回一個String^ 對象的wchar_t*指針。

// Concatenation auto str1 = "Hello" + " World";auto str2 = str1 + " from C++/CX!"; auto str3 = String::Concat(str2, " and the String class");// Comparisonif (str1 == str2) { /* ... */ }if (str1->Equals(str2)) { /* ... */ }if (str1 != str2) { /* ... */ }if (str1 < str2 || str1 > str2) { /* ... */};int result = String::CompareOrdinal(str1, str2);if(str1 == nullptr) { /* ...*/};if(str1->IsEmpty()) { /* ...*/};// Accessing individual characters in a String^auto it = str1->Begin();char16 ch = it[0];

?

String類型的轉換

String類型可以和標準C++的wstring進行互相的轉換

// compile with: /ZW #include <string>using namespace std; using namespace Platform;int main( array<String^>^ args ) {// Create a String^ variable statically or dynamically from a literal string. String^ str1 = "AAAAAAAA";// Use the value of str1 to create the ws1 wstring variable.wstring ws1( str1->Data() ); // The value of ws1 is L"AAAAAAAA".// Manipulate the wstring value.wstring replacement( L"BBB" );ws1 = ws1.replace ( 1, 3, replacement );// The value of ws1 is L"ABBBAAAA".// Assign the modified wstring back to str1. str1 = ref new String( ws1.c_str() ); return 0; }

?

?

轉載于:https://www.cnblogs.com/linzheng/archive/2012/07/29/2614014.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Windows 8 C++/CX字符串的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。