Comparing the overhead of storing strings separately vs. in a vector

#include <iostream> #include <vector> using namespace std; int main() { vector<string> v = {"It", "is", "not", "snowing", "today"}; for(string vi:v) { cout << &vi << ":" << vi << endl; } cout << "Total size: " << sizeof(v) << "bytes" << endl << endl; string it = "It", is = "is", na = "not", snowing = "snowing", today = "today"; int it_sz = sizeof(it); int is_sz = sizeof(is); int na_sz = sizeof(na); int snowing_sz = sizeof(snowing); int today_sz = sizeof(today); int total_sz = it_sz + is_sz + na_sz + snowing_sz + today_sz; cout << &it << ": " << it << " (" << it_sz << "bytes)" << endl; cout << &is << ": " << is << " (" << is_sz << "bytes)" << endl; cout << &na << ": " << na << " (" << na_sz << "bytes)" << endl; cout << &snowing << ": " << snowing << " (" << snowing_sz << "bytes)" << endl; cout << &today << ": " << today << " (" << today_sz << "bytes)" << endl; cout << "Total size: " << total_sz << "bytes" << endl; /* 0x7ffc2329cdc0:It 0x7ffc2329cdc0:is 0x7ffc2329cdc0:not 0x7ffc2329cdc0:snowing 0x7ffc2329cdc0:today Total size: 24bytes 0x7ffc2329cd40: It (32bytes) 0x7ffc2329cd60: is (32bytes) 0x7ffc2329cd80: not (32bytes) 0x7ffc2329cda0: snowing (32bytes) 0x7ffc2329cdc0: today (32bytes) Total size: 160bytes */ return 0; }