I am modernizing a large, legacy MFC codebase which contains a veritable medley of string types:
- CString
- std::string
- std::wstring
- char*
- wchar_t*
- _bstr_t
I'd like to standardize on a single string type internally, and convert to other types only when absolutely required by a third-party API (i.e. COM or MFC functions). The question my coworkers and I are debating; which string type should we standardize on?
I would prefer one of the C++ standard strings: std::string or std::wstring. I'm personally leaning toward std::string, because we do not have any need for wide characters - it is an internal codebase with no customer-facing UI (i.e. no need for multiple-language support). "Plain" strings allow us to use simple, unadorned string literals ("Hello world" vs L"Hello world" or _T("Hello world")).
Is there an official stance from the programming community? When faced with multiple string types, what is typically used as the standard 'internal' storage format?
std::wstring
is a good fit for that platform; so isstd::vector<wchar_t>
. – Hierodulestd::wstring
. With narrow strings you'd need conversions all over the place. Note: since you don't already know this, you're not a good choice for person to do the job, it's basics. That choice is your manager's fault. – Denazify_T("Hello world")
, theT
macros were obsoleted in the year 2000 by the introduction of Layer for Unicode, and today our tools can't produce executables for the Windows versions (9x) that these macros target. I understand it's a legacy codebase. But when your task is to clean it up, mentioningT
macros as convenient is absurd and very counter-productive. – Denazify