• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ and Strings

Apathetic

Platinum Member
While I was reading this thread, I was thinking about all the different ways you could declare a string in MS C++ (especially if you throw in MFC and ATL). Here's what I came up with. Which ones am I missing and which ones did you guys hate dealing with the most?

char *
CHAR *
wchar *
wchar_t *
TCHAR
LPSTR
LPCSTR
BSTR
_bstr_t
CComBSTR
CString
LPOLESTR


Dave
 
And in Java:
char[]
String
StringBuffer

That's it!

As for C/C+ could you include streams? If you want to get fancy how about vector<char>?
 
You forgot STL's string, and as IHMJ said vectors of any said type. You also forgot standard array types such as char[], wchar_t[], etc.

Also keep in mind that TCHAR is a typedef of either char or wchar_t depending on whether Unicode is defined in the Windows app. LPSTR, LPTSTR, LPCSTR, LPCTSTR are all typedefs of their respective types (char*, TCHAR*, const char* and const TCHAR*), so they also don't count. I believe BSTR is a typedef for _bstr_t, and in that vein you left out WCHAR which is a typedef of wchar_t. CString of the ATL class variety, one which I personally love. CString of the MFC variety is useful if you're working in MFC already. If you're being as meticulous as you seem, you forgot the const versions of everything in your list. And finally, I believe you're missing the most hideous one of all... the VARIANT string.
 
^^ agreed... Java's implementation is freaking AWESOME.

But in C++, I prefer the STL string class. It's good stuff 🙂
 
A string is just a group of chars in a row in memory in C for embedded devices so you can do just about anything with just a pointer.

But this thread is about C++ so this is a worthless post. That being said I don't like C++; I prefer to know what's going on behind the scenes code-wise. 🙂
 
i tend to think STL strings are pretty nice to use.

CComBSTR and _Bstr_t are not strings, they are wrappers to BSTR.

the only reason there is a BSTR is for COM and compatibility across VB, c# etc.

that really isnt fair to say those even count. i mean if you are going to count language compatibility wrappers like BSTR , you should count say jstrings in JNI as part of java.


TCHAR

is also not really a string. its a macro for unicode, that automatically converts to char or wchar depending on preprocessor flags



LPSTR
LPCSTR

these 2 are also not really strings. these are pointers and its a typedef of char* and const char*.

LPTSTR is in theory also a tchar pointer similar to those two.


so in reality , the only real string classes that are not pointers, or wrappers, are char* , wchar * , BSTR and std:string and cstring. std string is also really just a generalization of basic_string<char> so its really just a wrapper of char * also. same with std:wstring which is really basic_String<wchar_t>. and cstring is also some sort of wrapper.


so yeah.... theres a lot of conversions and wrappers that have been written over the years. but if you really think about it , since everything supports unicode now, we really only need wstring / wchar_t *. granted java has just String. but its much less flexible a language due to that. C++ strings are just really double or single byte streams and you can do lots of optimizations and such.

You really should like C++. since all these string types are really simple, and are exactly like C. i mean you could implement all of them in C with structs , and extractors and overloading.
 
Yup. 9th circle of hell pretty much sums it up. Especially when you're working on a project that needs to support several of them. *whimpers*

Dave

Originally posted by: Sc4freak
Link

Basically the ninth circle of hell.

 
While I certainly agree with you that several of them aren't really true strings, they are things I have to deal with. The stuff I write (services in C++) tends to be the glue that holds a lot of our infrastructure together. I make calls to COM components, C API style DLLs, and other C++ libraries, some unicode, some not. Translating all these string types from one to another can be a major pain. Dealing with "strings" in C++ in the Microsoft world is anything other than trivial. I don't know of any other language + platform combination that's anywhere near as complex.

Dave

Originally posted by: hans007
i tend to think STL strings are pretty nice to use.

CComBSTR and _Bstr_t are not strings, they are wrappers to BSTR.

the only reason there is a BSTR is for COM and compatibility across VB, c# etc.

that really isnt fair to say those even count. i mean if you are going to count language compatibility wrappers like BSTR , you should count say jstrings in JNI as part of java.


TCHAR

is also not really a string. its a macro for unicode, that automatically converts to char or wchar depending on preprocessor flags



LPSTR
LPCSTR

these 2 are also not really strings. these are pointers and its a typedef of char* and const char*.

LPTSTR is in theory also a tchar pointer similar to those two.


so in reality , the only real string classes that are not pointers, or wrappers, are char* , wchar * , BSTR and std:string and cstring. std string is also really just a generalization of basic_string<char> so its really just a wrapper of char * also. same with std:wstring which is really basic_String<wchar_t>. and cstring is also some sort of wrapper.


so yeah.... theres a lot of conversions and wrappers that have been written over the years. but if you really think about it , since everything supports unicode now, we really only need wstring / wchar_t *. granted java has just String. but its much less flexible a language due to that. C++ strings are just really double or single byte streams and you can do lots of optimizations and such.

You really should like C++. since all these string types are really simple, and are exactly like C. i mean you could implement all of them in C with structs , and extractors and overloading.

 
Originally posted by: Apathetic
While I certainly agree with you that several of them aren't really true strings, they are things I have to deal with. The stuff I write (services in C++) tends to be the glue that holds a lot of our infrastructure together. I make calls to COM components, C API style DLLs, and other C++ libraries, some unicode, some not. Translating all these string types from one to another can be a major pain. Dealing with "strings" in C++ in the Microsoft world is anything other than trivial. I don't know of any other language + platform combination that's anywhere near as complex.

Dave

Originally posted by: hans007
i tend to think STL strings are pretty nice to use.

CComBSTR and _Bstr_t are not strings, they are wrappers to BSTR.

the only reason there is a BSTR is for COM and compatibility across VB, c# etc.

that really isnt fair to say those even count. i mean if you are going to count language compatibility wrappers like BSTR , you should count say jstrings in JNI as part of java.


TCHAR

is also not really a string. its a macro for unicode, that automatically converts to char or wchar depending on preprocessor flags



LPSTR
LPCSTR

these 2 are also not really strings. these are pointers and its a typedef of char* and const char*.

LPTSTR is in theory also a tchar pointer similar to those two.


so in reality , the only real string classes that are not pointers, or wrappers, are char* , wchar * , BSTR and std:string and cstring. std string is also really just a generalization of basic_string<char> so its really just a wrapper of char * also. same with std:wstring which is really basic_String<wchar_t>. and cstring is also some sort of wrapper.


so yeah.... theres a lot of conversions and wrappers that have been written over the years. but if you really think about it , since everything supports unicode now, we really only need wstring / wchar_t *. granted java has just String. but its much less flexible a language due to that. C++ strings are just really double or single byte streams and you can do lots of optimizations and such.

You really should like C++. since all these string types are really simple, and are exactly like C. i mean you could implement all of them in C with structs , and extractors and overloading.



Haha nice, i also write windows services. And I have to tie to gether SDKs from various other companies so they are all written in random "whatever those companies felt like" so its a real pain. Once you learn it though its really not that bad. I mean at worst its like 10-12 things.
 
Back
Top