The string class takes care of this with its constructors and/or its overloaded operator=
#include <iostream> #include <string> #include <cstdlib> int main() { char cname[] = "Bob"; string name; name = "Bob"; // or name = cname; }