By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,563 Members | 1,180 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,563 IT Pros & Developers. It's quick & easy.

How to convert std:string into basic string

100+
P: 151
How can we convert std::string into basic string?
Sep 16 '09 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,916
std:string is a specialisation of basic_string as follows:

typedef basic_string<char> string;

There is no need to convert it.
Sep 16 '09 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
I presume you mean to convert std::string to a BSTR. Yes?

If so, you use the _bstr_t class that enacpeulates a BSTR. One of the constructors takes a char* argument for a C string. Just create your _bstr_t object using std::string.C_str() as an argument.

Expand|Select|Wrap|Line Numbers
  1. string data("hello");
  2. _bstr_t obj(data.c_str());
http://msdn.microsoft.com/en-us/libr...d6(VS.71).aspx
Sep 16 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.