what is the diff between String and string?
-
is there a way to convert String to string ? I am using c++.net forms in the form.h file when i try to get the name of a file from the texbox and open it , i get an error. it sayd it cant convert the typr _wchar to char !!! i used ifstream infile; infile.open(fileName);
-
is there a way to convert String to string ? I am using c++.net forms in the form.h file when i try to get the name of a file from the texbox and open it , i get an error. it sayd it cant convert the typr _wchar to char !!! i used ifstream infile; infile.open(fileName);
wchar is a wide string. you need to use wstring instead of string. You can also use _bstr_t to convert automagically between them, I think it's in comutils.h. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
wchar is a wide string. you need to use wstring instead of string. You can also use _bstr_t to convert automagically between them, I think it's in comutils.h. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
thanks christian can you write it as a code i am not so sure how to use _bstr_t eg. char me; Char you; is it then right to say me = _bstr_t(you) and can it be used for char arrays as well?
-
thanks christian can you write it as a code i am not so sure how to use _bstr_t eg. char me; Char you; is it then right to say me = _bstr_t(you) and can it be used for char arrays as well?
_bstr_t is a string wrapper that internally contains both a wide and a narrow string. It would treat a char as a char array of one. I would use it like this: some COM function(BSTR myBSTR, BSTR * returnBSTR) { std::string s(dynamic_cast_bstr_t(myBSTR)); ... use the string *returnBSTR = _bstr_t(s.c_str()).detach(); } The syntax is probably horribly wrong, it's 12 months since I did any serious C++, but certainly that is mostly right. My string is being passed a char * in it's constructor, which comes from a temporarily created _bstr_t. The cast to char* may not be necessary, the point is that _bstr_t will construct itself from the BSTR ( wide string ) and then it's operator char* will perform the conversion for you. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder