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

Trying to convert _btsrt_t to string

P: n/a
Hi

I'm trying to retrive data from an SQL Server and use this data in
another query. Methods that retireve data with ADO give me a _btstr_t
data type and I want to convert it to a more standard std::string.

I've tried to do this

valField1 = pRstAuthors->Fields->GetItem("codigo")->Value;
printf("As _bstr_t: %s\n", (LPCSTR) valField1);
string z((const char *)valField1);
printf("As string: %s", z);
The first printf works ok and prints "As _bstr_t: 0001". The second one
hangs up the application... :(

I want to make this prints to be sure that convertion works well..

Any idea ?

Thanks in advance

J

PD: I'm using VC++ 6.0
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Javier" <jl****@manresa.net> schrieb im Newsbeitrag news:ct**********@news.ya.com...
Hi

I'm trying to retrive data from an SQL Server and use this data in
another query. Methods that retireve data with ADO give me a _btstr_t
data type and I want to convert it to a more standard std::string.

I've tried to do this

valField1 = pRstAuthors->Fields->GetItem("codigo")->Value;
printf("As _bstr_t: %s\n", (LPCSTR) valField1);
string z((const char *)valField1);
printf("As string: %s", z);


You cannot printf a std::string like that. One more reason to use streams. To print a std::string pass z.c_str() to printf.

HTH
Heinz
Jul 23 '05 #2

P: n/a
Heinz Ozwirk wrote:
"Javier" <jl****@manresa.net> schrieb im Newsbeitrag news:ct**********@news.ya.com...
Hi

I'm trying to retrive data from an SQL Server and use this data in
another query. Methods that retireve data with ADO give me a _btstr_t
data type and I want to convert it to a more standard std::string.

I've tried to do this

valField1 = pRstAuthors->Fields->GetItem("codigo")->Value;
printf("As _bstr_t: %s\n", (LPCSTR) valField1);
string z((const char *)valField1);
printf("As string: %s", z);

You cannot printf a std::string like that. One more reason to use streams. To print a std::string pass z.c_str() to printf.

HTH
Heinz

It worked, thanks a lot !
J
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.