1、示例**:
// test.cpp : 定義控制台應用程式的入口點。
//#include "stdafx.h"
#include #include using namespace std;
int _tmain(int argc, _tchar* argv)
{ cout << "字串占用位元組數的求法:"<< endl;
cout << "sizeof(int) = " << sizeof(int) << endl;
cout << "sizeof(short) = " << sizeof(short) << endl;
cout << "sizeof(long) = " << sizeof(long) << endl;
cout << "sizeof(float) = " << sizeof(float) << endl;
cout << "sizeof(double) = " << sizeof(double) << endl;
cout << "sizeof(bool) = " << sizeof(bool) << endl;
cout << "sizeof(void*) = " << sizeof(void*) << endl << endl;
cout << "sizeof(char) = " << sizeof(char) << endl;
cout << "sizeof(wchar_t) = " << sizeof(wchar_t) << endl;
cout << "sizeof(tchar) = " << sizeof(tchar) << endl << endl;
cout << "窄字元(ansi)" << endl;
char szstr1 = "hello world!";
char *pstr2 = "hello world!";
cout << sizeof(szstr1) << endl;
cout << sizeof(char) * strlen(pstr2) <
2、當專案使用unicode字符集時,執行結果如下:
3、當專案使用未設定(窄字元)時,執行結果如下:
4、使用多位元組字符集時:
占用位元組數求法
字串占用位元組數 ansi char szstr abc 占用位元組數求法 sizeof szstr char psz defgh 占用位元組數求法 strlen psz sizeof char unicode wchar t szwstr l abc 占用位元組數求法 sizeof szwstr ...
Oracle 漢字占用位元組數
在oracle中乙個字元特別是中文字元佔幾個位元組是與字符集有關的。比如gbk,漢字就會佔兩個位元組,英文1個 如果是utf 8,漢字一般佔3個位元組,英文還是1個。但是一般情況下,我們都認為是兩個位元組處理,因為oracle安裝時候預設我們都選擇gbk的編碼格式,但是我們在頁面做輸入字串長度的校驗...
List與陣列占用位元組數
想看一下list序列化後占用多少個 位元組,測試程式如下 public static void main string args throws ioexception system.out.println 元素數 list.size bytearrayoutputstream baos new by...