靓丽时尚馆

位置:首页 > 健康生活 > 心理

c++如何查看字节

心理1.85W
c++如何查看字节

字节在计算机科学领域,字节指的是8位内存单元,常用byte/B表示,是度量计算机存储空间大小的度量单位。我们说的1KB就是1024个字节,即1024*8位。

在C++里,字节定义稍有不同。一个字节包含的位数可表示的状态(例如8位可表示的状态是256种)应足以覆盖基本字符集(ASCII)字符的个数。通常的C++实现中使用的字符系统是ASCII,所以在通常C++实现中,一个字节就是8位。但是在一些采用Unicode字符系统的C++实现中,可能使用16位或者32位字节。

#include<iostream>

#include <limits>

using namespace std

int main()

{

cout << "type: tt" << "************size**************"<< endl

cout << "bool: tt" << "所占字节数:" << sizeof(bool)

cout << "t最大值:" << (numeric_limits<bool>::max)()

cout << "tt最小值:" << (numeric_limits<bool>::min)() << endl

cout << "char: tt" << "所占字节数:" << sizeof(char)

cout << "t最大值:" << (numeric_limits<char>::max)()

cout << "tt最小值:" << (numeric_limits<char>::min)() << endl

cout << "signed char: t" << "所占字节数:" << sizeof(signed char)

cout << "t最大值:" << (numeric_limits<signed char>::max)()

cout << "tt最小值:" << (numeric_limits<signed char>::min)() << endl

cout << "unsigned char: t" << "所占字节数:" << sizeof(unsigned char)

cout << "t最大值:" << (numeric_limits<unsigned char>::max)()

cout << "tt最小值:" << (numeric_limits<unsigned char>::min)() << endl

cout << "wchar_t: t" << "所占字节数:" << sizeof(wchar_t)

cout << "t最大值:" << (numeric_limits<wchar_t>::max)()

cout << "tt最小值:" << (numeric_limits<wchar_t>::min)() << endl

cout << "short: tt" << "所占字节数:" << sizeof(short)

cout << "t最大值:" << (numeric_limits<short>::max)()

cout << "tt最小值:" << (numeric_limits<short>::min)() << endl

cout << "int: tt" << "所占字节数:" << sizeof(int)

cout << "t最大值:" << (numeric_limits<int>::max)()

cout << "t最小值:" << (numeric_limits<int>::min)() << endl

cout << "unsigned: t" << "所占字节数:" << sizeof(unsigned)

cout << "t最大值:" << (numeric_limits<unsigned>::max)()

cout << "t最小值:" << (numeric_limits<unsigned>::min)() << endl

cout << "long: tt" << "所占字节数:" << sizeof(long)

cout << "t最大值:" << (numeric_limits<long>::max)()

cout << "t最小值:" << (numeric_limits<long>::min)() << endl

cout << "unsigned long: t" << "所占字节数:" << sizeof(unsigned long)

cout << "t最大值:" << (numeric_limits<unsigned long>::max)()

cout << "t最小值:" << (numeric_limits<unsigned long>::min)() << endl

cout << "double: t" << "所占字节数:" << sizeof(double)

cout << "t最大值:" << (numeric_limits<double>::max)()

cout << "t最小值:" << (numeric_limits<double>::min)() << endl

cout << "long double: t" << "所占字节数:" << sizeof(long double)

cout << "t最大值:" << (numeric_limits<long double>::max)()

cout << "t最小值:" << (numeric_limits<long double>::min)() << endl

cout << "float: tt" << "所占字节数:" << sizeof(float)

cout << "t最大值:" << (numeric_limits<float>::max)()

cout << "t最小值:" << (numeric_limits<float>::min)() << endl

cout << "size_t: t" << "所占字节数:" << sizeof(size_t)

cout << "t最大值:" << (numeric_limits<size_t>::max)()

cout << "t最小值:" << (numeric_limits<size_t>::min)() << endl

cout << "string: t" << "所占字节数:" << sizeof(string) << endl

// << "t最大值:" << (numeric_limits&ltstring>::max)() << "t最小值:" << (numeric_limits<string>::min)() << endl

cout << "type: tt" << "************size**************"<< endl

return 0

标签:字节 查看