Trying to convert _btsrt_t to string

J

Javier

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
 
H

Heinz Ozwirk

Javier said:
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
 
J

Javier

Heinz said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top