strlen 与 sizeof
#include <stdio.h> #include <string.h> #include <iostream> int main() { char name[7] = "morgan"; std::cout << strlen(name) << " " << sizeof(name) << std::endl; //6 7 const char* name2 = "morgan"; std::cout << strlen(name2) << " " << sizeof(name2) << std::endl; //6 8 std::cout << strlen("morgan") << " " << sizeof("morgan") << std::endl; //6 7 return 0; }