1

I am trying to convert my string to a cstring in an mfc Application. I have searched this forum for hours without any result.

my code is:

void CSokevinduView::OnBnClickedsoker()
{
string O1,O2,O3,info;


ifstream Innfil;
Innfil.open("SQLPResponse.txt");
Innfil.ignore();
getline(Innfil,O1);
getline(Innfil,O2);
getline(Innfil,O3);
getline(Innfil,info);
Innfil.close();

    m_sok=info;

m_sok is a cstring btw.

The problem is that "m_sok" dont want to be like "info".

I am very New to this as you can see from my coding.

Thx in advance.

1 Answers1

1

Use the c_str() method of string.

m_sok = info.c_str();
Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
  • If the `_UNICODE` preprocessor symbol is defined, the line above invokes an MBCS to Unicode conversion, using the current thread's locale. If `info` contains only ASCII characters, this is not an issue. Otherwise the results can be undesirable. [CStringT::operator=](https://msdn.microsoft.com/en-us/library/wxeexhs7.aspx) sometimes does more than you asked for. – IInspectable Mar 03 '15 at 21:36