The following is the test procedure:
#include <iostream>
#include <vector>
#include <string>
#include <cstddef>
using namespace std;
int main()
{
string word1 = "Teddy";
string word2 = "Bear";
vector<int> vec1{
0,1,2,3,4 };
vector<int> vec2{
0,1,2 };
vector<string> vec3 = {
"Teddy","Bear" };
cout << "size of int is " << sizeof(int) << ".\n";
cout << "size of long is " << sizeof(long) << ".\n";
cout << "size of long long is " << sizeof(long long) << ".\n";
cout << "size of short is " << sizeof(short) << ".\n";
cout << "size of char is " << sizeof(char) << ".\n";
cout << "size of 'word1' is " << sizeof word1 << ".\n";
cout << "size of 'word2' is " << sizeof word2 << ".\n";
cout << "size of 'vec1' is " << sizeof vec1 << ".\n";
cout << "size of 'vec2' is " << sizeof vec2 << ".\n";
cout << "size of 'vec3' is " << sizeof vec3 << ".\n";
return 0;
}
My computer's output is:
(each computer is not necessarily the same)
by the law known vector, sizeof string value has nothing to do with the content stored .
The sizeof of the array is not listed in this program. The size of each element of the array is multiplied by the number.
[C++ Primer(5th Edition) Exercise] Exercise Program-Chapter4 (Chapter 4)