_bstr_t to string-newbie
-
Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far
I actually know this is simple, but I forget the answer. I would repost this question in the COM forum if I was you. INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far
See The Complete Guide to C++ Strings, Part II - String Wrapper Classes[^]
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far
Mr. Dunn already pointed you to his FAQ which is probably the best resource available on CP but just in case, here are some ways you can get it done. NOTE: These will only work if the BSTR does not contain embedded NULL's as would occur in a BYTE array. If you are sure you are dealing with null terminated strings in the BSTR like when using MSXML, these will get you by. // Using the CString constructor _bstr_t bstrTemp("This is a test\n"); CString sTemp1((BSTR)bstrTemp); TRACE(sTemp1); // For when you don't have the luxury of using the constructor CString sTemp2; sTemp2.Format("%s",(LPCTSTR)bstrTemp); TRACE(sTemp2);
-
See The Complete Guide to C++ Strings, Part II - String Wrapper Classes[^]
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Mr. Dunn already pointed you to his FAQ which is probably the best resource available on CP but just in case, here are some ways you can get it done. NOTE: These will only work if the BSTR does not contain embedded NULL's as would occur in a BYTE array. If you are sure you are dealing with null terminated strings in the BSTR like when using MSXML, these will get you by. // Using the CString constructor _bstr_t bstrTemp("This is a test\n"); CString sTemp1((BSTR)bstrTemp); TRACE(sTemp1); // For when you don't have the luxury of using the constructor CString sTemp2; sTemp2.Format("%s",(LPCTSTR)bstrTemp); TRACE(sTemp2);
-
Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string Thanks a lot for everything so far
antonaras wrote:
Hi again guys a simple guestion how can i convert(assighn) a variable of type _bstr_t to string
_bstr_t hi("alok"); std::string str((LPCTSTR)hi) ;
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You