int 4字节 long int 4 字节
float 4字节 double 8字节
bool 1字节 char 1字节
也可以sizeof来获取
char字符类型取值范围有限,只能用来表示有限ANSI字符。如果要表示使用广泛的UNICODE字符,例如中文字符,char就鞭长莫及了。
为了表示UNICODE字符,c++提供了另一种字符类型wchar_t,它占2个字节,也可以输出一个中文字符。
// rw.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
wchar_t cChinese = L'中';
wstring strChina(L"中国");
wcout.imbue(locale("chs"));
wcout<<cChinese<<endl;
wcout<<strChina<<endl;
string strMorning("Good Morning!");
int nLength = strMorning.length();
string::size_type nPos = strMorning.find('o');
cout<<strMorning<<"的长度是:"<<nLength<<"\n在位置"<<nPos<<"有一个字符O"<<endl;
system("pause");
return 0;
}