c Windows程式設計 字串

2021-10-12 19:22:41 字數 3199 閱讀 7970

#include

#include

#include

#include

using

namespace std;

/*多字元(multichar)也就是ansi編碼的方式,而寬字元(widechar)也就是unicode編碼的方式

wchar unicode字元

pwstr 指向unicode字串的指標

pcwstr 指向乙個恆定的unicode字串的指標

對應的ansi資料型別為char,lpstr和lpcstr。

ansi/unicode通用資料型別為tchar,ptstr,lpctstr。

如何判斷乙個文字檔案是ansi還是unicode?

判斷如果文字檔案的開頭兩個位元組是0xff和0xfe,那麼就是unicode,否則是ansi。

*//*

功能:拼接兩個字串

stringcchcatw(

strsafe_lpwstr pszdest,//目標字串,不能定義strsafe_lpwstr,要定義為wchar_t型別,因為cchdest用到的_countof(array)必須是陣列

size_t cchdest,//目標快取大小

strsafe_lpcwstr pszsrc)//源快取字串

這些函式的ex版本多了三個引數:size_t * pcchremaining 返回目標緩衝區還有多少個字元未被使用

lptstr * ppszdesend 指向目標終止符『\0』位置

標識位:strsafe_??處理函式成功或失敗後的目標緩衝區字元;

功能:字串比較函式

comparestringw(

lcid locale, 地方識別符號:可以呼叫getthreadlocale獲得

dword dwcmpflags, 帶 norm_??? 字首的乙個或多個常數,它們定義了象「忽略大小寫」這樣的一些選項

pcnzwch lpstring1,第乙個字串

int cchcount1, 第乙個字串長度

pcnzwch lpstring2,第二個字串

int cchcount2); 第二個字串長度

返回值 1小於 2等於 3大於

intwinapi 字串比較的另外乙個函式(根據碼位比較)

comparestringordinal(

lpcwch lpstring1,

int cchcount1,

lpcwch lpstring2,

int cchcount2,

bool bignorecase//按系統大寫表資訊執行比較為true,字串比較填false

);*/

void

main()

; size_t lengh;

hr=stringcchcat

(ptstr_ch,

_countof

(ptstr_ch)

, ptstr_ch1)

;//拼接字串

if(hr != s_ok)

//strsafe_e_invalid_parameter 將null傳給了乙個引數 strsafe_e_insufficient_buffer 指定目標緩衝區太小

else

stringcchcopy

(ptstr_ch2,

_countof

(ptstr_ch2)

, ptstr_ch1)

;//字串拷貝

wcout << ptstr_ch2 << endl;

stringcchprintf

(ptstr_ch3,

_countof

(ptstr_ch3)

, l"要拷貝的:%s"

, ptstr_ch1)

;//列印到字串

wcout << ptstr_ch3 << endl;

stringcchlength

(ptstr_ch3,

_countof

(ptstr_ch3)

,&lengh)

; cout << lengh << endl;

stringcchgets

(ptstr_ch4,

_countof

(ptstr_ch4));

//獲得乙個字元,不支援中文

//wcout << ptstr_ch4 << endl;

cout<<

"getthreadlocale "

<< getthreadlocale << endl;

//獲取程序地方標識

cout<<

"比較結果:"

<<

comparestring

(getthreadlocale()

,norm_ignorecase, l"你",20

, l"我",20

)

"比較結果:"

<<

comparestring

(getthreadlocale()

, norm_ignorecase, l"你",20

, l"你",20

)<< endl;

cout <<

"比較結果:"

<<

comparestring

(getthreadlocale()

, norm_ignorecase, l"我",20

, l"你",20

)<< endl;

cout <<

"比較結果:"

<<

comparestringordinal

( l"你",20

, l"我",20

,false

)<< endl;

cout <<

"比較結果:"

<<

comparestringordinal

( l"你",20

, l"你",20

,false

)<< endl;

cout <<

"比較結果:"

<<

comparestringordinal

( l"我",20

, l"你",20

,false

)<< endl;

cin.

get();

}

C Windows平台字串編碼轉換

一 windows api 本文介紹使用windows api進行字元編碼的轉換,涉及widechartomultibyte和multibytetowidechar2個api,api介面名中的multibyte對應著多位元組編碼,如ascii utf 8等都是多位元組編碼,而widechar字面意思...

ORACLE in 字串,字串,字串

因為傳進來的引數是 字串,字串,字串,要實現in 字串,字串,字串 select from htl price p where p.hotel id 30073328 and p.able sale date between to date 2009 03 27 yyyy mm dd and to ...

C windows程式設計錯誤集

1,c free c windows socket程式設計報錯如下 error c users getway desktop golftest v3.o golftest v3.c text 0x26b undefined reference to send 16 error c users get...