string conversion

A

alex

i have a string "dasfk" stored in a variable of type string and i want to
convert it to const _bstr_t, anybody know?
 
V

Victor Bazarov

alex said:
i have a string "dasfk" stored in a variable of type string and i want to
convert it to const _bstr_t, anybody know?

Whoever defines this type _bstr_t (a compiler or library) should probably
have some functions for converting a character array into it (or getting
normal characters from it). Don't you have the documentation for that?
IOW, "_bstr_t" is not a standard C++ type. You will probably get more
help in a newsgroup dedicated to the compiler or the library (or the OS)
where this type is used.

V
 
J

Julie

alex said:
i have a string "dasfk" stored in a variable of type string and i want to
convert it to const _bstr_t, anybody know?


const _bstr_t bstr = str.c_str();
 
P

Phlip

alex said:
i have a string "dasfk" stored in a variable of type string and i want to
convert it to const _bstr_t, anybody know?

This newsgroup is qualified to discuss std::string, but not _bstr_t. Use
Google Groups to learn what newsgroups know about it.

However, to convert a std::string z to anything that accepts a char const *,
use z.c_str().
 
A

alex

Phlip said:
This newsgroup is qualified to discuss std::string, but not _bstr_t. Use
Google Groups to learn what newsgroups know about it.

However, to convert a std::string z to anything that accepts a char const *,
use z.c_str().

z.c_str() results in successful compilation of the code but the database
connection i'm trying to make doesn't work. I think this is purely a string
conversion problem because when I put the database connection string in as
"bla bla" it works.
 
P

Phlip

alex said:
z.c_str() results in successful compilation of the code but the database
connection i'm trying to make doesn't work. I think this is purely a string
conversion problem because when I put the database connection string in as
"bla bla" it works.

So given...

_bstr_t strCnn(z.c_str());

....if you put a breakpoint on that line, step over it, and then hover the
mouse pointer over strCnn, what does it say? Is it as good a connect string
as you formerly hard-coded? Is it missing a semicolon? or is it full of
garbage?

When trivial string assignments compile correctly, suspect their contents
and not their conversion operations.
 
J

Jorge Rivera

alex said:
i have a string "dasfk" stored in a variable of type string and i want to
convert it to const _bstr_t, anybody know?

Isn't _bstr_t a Microsoft thing?
If it is, try in Microsoft.public.visualc.

I think what you have to do is:

_bstr_t mBstr = _bstr_t("daskf");

and then pass this to whatever function you need.

JLR
 
A

alex

Jorge Rivera said:
Isn't _bstr_t a Microsoft thing?
If it is, try in Microsoft.public.visualc.

I think what you have to do is:

_bstr_t mBstr = _bstr_t("daskf");

and then pass this to whatever function you need.

JLR

_bstr_t mBstr = _bstr_t("daskf");

works if "daskf" is the hardcoded connection string, if i pass in a variable
or pointer to the string read in from console input, i can't get that to
work. I've verified with breakpoints that i'm passing around
variables/pointers that are properly set to the connection string. Every
example on the internet seems to use a hardcoded string. It's a string type
issue.
 

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

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,463
Latest member
FinleyMoye

Latest Threads

Top