关于字节的一些发现

float:通常占用4字节。

long long:通常占用8字节。

long:在32位系统中通常占用4字节,在64位系统中可能占用8字节。 string:std::string的大小不是固定的,因为它包含一个指向动态分配的字符数组的指针以及其他一些成员变量(如长度和容量)。通常,std::string对象本身的大小约为24字节(在64位系统上),但这不包括它所管理的字符数据的空间。

vector 和 vector:std::vector的大小也不是固定的。它包含指向动态分配的数组的指针、当前大小和容量等信息。通常,std::vector对象本身的大小约为24字节(在64位系统上),但这不包括它所管理的元素的空间。

int:通常占用4字节。

stringstream:std::stringstream是一个复杂的类,用于执行字符串的格式化和解析。它的大小取决于内部实现,通常较大,可能在40字节以上。

bool:通常占用1字节。

char:总是占用1字节。

double:通常占用8字节。

点个赞再走呗

#include <bits/stdc++.h>
using namespace std;
int main() {
	cout << "float:" << sizeof (float) << endl;
	cout << "long long:" << sizeof (long long) << endl;
	cout << "long:" << sizeof (long) << endl;
	cout << "string:" << sizeof (string) << endl;
	cout << "vector<int>:" << sizeof (vector<int>) << endl;
	cout << "vector<long long>:" << sizeof (vector<long long>) << endl;
	cout << "int:" << sizeof (int) << endl;
	cout << "stringstream:" << sizeof (stringstream) << endl;
	cout << "bool:" << sizeof (bool) << endl;
	cout << "char:" << sizeof (char) << endl;
	cout << "double:" << sizeof (double) << endl;
	return 0;
}

0 条评论

目前还没有评论...