C++ › Strings & string_view

What is std::string and how does it differ from a C-string?

Beginner

Answer

std::string is a class that owns and manages a dynamically-sized sequence of characters, handling memory automatically, growth, and many operations (concatenation, search, substr). A C-string is a raw null-terminated char array with manual memory management and no bounds safety. std::string is the safe, convenient default in C++.
std::string s = "hello";
s += " world";      // grows automatically
const char* c = "hi";  // C-string, manual
Real-world example Using std::string avoids buffer-overflow bugs common with fixed char[] buffers.

Common follow-ups: Who manages std::string's memory? | Why is std::string safer than char[]?