Strings in C++
by kit
Using programming languages such as Ruby and Python (freedom languages?) in order to gain an advantage over over those stuck in the past is sometimes an everyday choice. Here’s a list to remind you of why you chose as you did.
- “I’m so sad”
- L”I’m so sad”
- W”I’m so sad”
- OLESTR
- SysAllocString(L”I’m so sad”)
- \_T(“I’m so sad”)
- \_TEXT(“I’m so sad”)
- BSTR
- CAtlString
- CAtlStringA
- CAtlStringW
- CComBSTR
- CSimpleStringT
- CString
- CStringA
- CStringT
- CStringW
- DBTYPE\_BSTR
- DBTYPE\_STR
- DBTYPE\_WSTR
- LPCSTR
- LPCTSTR
- LPCWSTR
- LPOLESTR
- LPSTR
- LPTSTR
- LPWSTR
- OLECHAR
- System::String
- TCHAR
- \_bstr\_t
- basic\_string<char>
- basic\_string<wchar\_t>
- char *
- std::string
- std::wstring
- wchar\_t *
These all essentially mean “string” in C++. This list is by no means comprehensive.




August 13th, 2006 at 01:43 PM Wrong. There is only one string type in C++. That is std::basic_string<...>. Your list include std::string and std::wstring which are typedefs of basic_string. All the other string types listed are proprietary and/or left for C support (char*). Most of your string types are microsoft specific, and in no way part of C++.
August 13th, 2006 at 01:50 PM The point is: being stuck in the world of C++ and having to "deal" with the lack of basic data types, like strings, just shows the age of the language. C/C++ will be around for systems programming for a while to come, but modern, dynamically typed languages are fun and simple simple simple.
August 13th, 2006 at 02:11 PM You do realize that Ruby, Java, Perl, PHP, Pyton etc etc all are written in C/C++ for a reason? I don't think anyone sane would bootstrap ruby with ruby. Maybe we should hope C stick around for a while longer so simple (as in not smart) developers like yourself have a scripting language to play with in the first place.
August 13th, 2006 at 02:22 PM No, complaining that you have to "deal" with a chosen framework's implementations just shows how misguided and uninformed language comparison can be. Phrakture's right: that list is basically a collection of Microsoft wrappers for either Win32, OLE, COM, or C libraries. If you're coding in one of those domains, either use the implementations that are given, find a 3rd-party implementation that is more C++ compliant (many elegant libraries exist), or write your own. The option to complain in order to try to start a language war would be better served if there was at least meaningful argument to back it up.
August 13th, 2006 at 06:00 PM wow lets stop the flame war before it starts.. this is pointless.
August 15th, 2006 at 09:24 PM The many string implementations is a real problem in C++ - think about it from a library perspective. I want to provide you some library that works with strings, but I want to do so as conveniently to you as possible. In order to do, I have to use your matching String implementation. This is simply not possible when you want your library to be used by many different people in many different environments. In such a case I chose the lowest common denominator would work best - ye ol' char* - doesn't mean I was happy about it.