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 Answer 1

1

Use the c_str() method of string.

m_sok = info.c_str();
Sign up to request clarification or add additional context in comments.

1 Comment

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= sometimes does more than you asked for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.