C-Style Char Arrays vs std::string
🟡 Intermediate
📖 Definition
C-strings are raw null-terminated ('\0') character arrays (char str[] = "hello";). ISO C++ provides std::string, a dynamic container wrapper that eliminates manual buffer management and overflow vulnerabilities.
💡 Code Example
#include <iostream>
#include <string>
int main() {
const char* cstr = "Hello C-String";
std::string cppstr = "Hello C++ std::string";
std::cout << cstr << "\n" << cppstr << "\n";
return 0;
}