評論公正地解釋了這一切。幫幫我?字符串矩陣的sizeof
string aZOM[][2] = {{"MoraDoraKora", "PleaseWorkFFS"},{"This is a nother strang.", "Orly?"}};
cout << sizeof("MoraDoraKora") <<" \n";
//Obviously displayes the size of this string...
cout << sizeof(aZOM[0][0]) << " \n";
//here's the problem, it won't display the size of the actual string... erm, what?
string example = aZOM[0][0];
cout << example << " \n";
cout << aZOM[0][1] << " \n";
//Both functions display the string just fine, but the size of referencing the matrix is the hassle.
注意;對於第一個你得到一個const char *的大小? – Skeen 2013-03-23 00:30:34
這似乎是更好的解釋。 :) – scones 2013-03-23 00:31:18
@Skeen你得到數組的大小,因爲數組不會經歷數組到指針的轉換作爲'sizeof'的操作數。 – 2013-03-23 00:31:48