Strings in C ++
**Strings in C++** In C++, strings can be handled in two primary ways: using **C-style character arrays** and the **`std::string`** class from the Standard Template Library (STL). Here's a structured overview: --- **1. C-Style Strings** - **Definition**: Arrays of characters terminated by a null character (`'\0'`). - **Declaration**: ```cpp char cstr1[] = "Hello"; // Automatically adds '\0' char cstr2[6] = {'H', 'e', 'l', 'l', 'o', '\0'}; ``` - **Key Functions** (from `<cstring>`): - `strlen(cstr)`: Returns length (excluding `'\0'`). - `strcpy(dest, src)`: Copies `src` to `dest`. - `strcat(dest, src)`: Appends `src` to `dest`. - `strcmp(cstr1, cstr2)`: Compares lexicographically (returns 0 if equal). - **Pitfalls**: - Buffer overflow risks (e.g., `strcpy` without checking sizes). - Manual memory management required. --- **2. `std::string` Class** - **Header**: `<string...