Code:#include<iostream> #include<cstring> using namespace std; int main() { string old_name; // presumably assign old_name somewhere in here. if(!old_name.empty()) // easy to read conditional. { char* new_name = new char[4]; strncpy(new_name, old_name.c_str(), 4); // do what you got to do with a non-empty c-string // All the messy c-string work is isolated here. cout << new_name << endl; } else { cout << "empty" << endl; } cin.get(); return 0; }