switch to std::string makes str[0] invalid on empty string rather than \0