Created
April 9, 2016 15:49
-
-
Save amullins83/b712465983cdc3983ee8d27cc316dd71 to your computer and use it in GitHub Desktop.
sizeof(string) does not give you the string's length.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using std::cout; | |
using std::endl; | |
using std::string; | |
int main() | |
{ | |
string sizeStr = "This is a test string that is rather long. Many bytes. Oh yes, quite a few bytes."; | |
cout << "The length of sizeStr is " << sizeStr.size() << endl; // The length of sizeStr is 81 | |
cout << "sizeof(sizeStr) returns " << sizeof(sizeStr) << endl; // sizeof(sizeStr) returns 4 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment