Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting type "string" to type "char"

Status
Not open for further replies.

hzt0qb

Programmer
Aug 13, 2001
3
ZA
Hi,

I need to convert a type "string" to a type "*char" in my MFC console application.

I'm pulling some values out of the registry and storing them in a [class.string]. I want to use this as a parameter to open a file using CFile.
but when I compile I get the error:
************************************************************
error C2664: 'Open' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
************************************************************

The values I am getting from the registry are REG_SZ's and my function to read the reg does not work storing the values as &quot;CHAR *VALUE&quot;

So I thought the solution would be to change the STRING's to CHAR's? If so how?

~Thanks
 
Promblem you have is not a problem conveting string to char*, but string to const char* (feel the difference:).
Use c_str() method.
 
Thanks mate,
This pointed me in the right direction...

;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top