C-Style Strings in C++

C++ supports C-style strings, which are arrays of characters terminated by a null character ('\0'). They are less safe and less convenient than std::string.

Example: Using C-Style Strings

#include <iostream>
#include <cstring>

int main() {
    char greeting[] = "Vanakkam";
    std::cout << greeting << std::endl;
    
    // Using strlen() from <cstring>
    std::cout << "Length: " << strlen(greeting) << std::endl;
    return 0;
}

Key Takeaways

  • C-style strings are arrays of characters ending with a null terminator.
  • Use functions from the <cstring> header for manipulation.
  • Prefer std::string for safer and more convenient string handling.