Solved

Conversion problem

Posted on 1998-11-04
6
185 Views
Last Modified: 2010-04-02
Looks like VC++ cannot convert automatically from string to CString as I get some error message.

Cf below for extract of the code as well as the error message.

string CashOrSwap;
      '
      '
      '
CString    m_HkdRunTime;

m_HkdRunTime = CashOrSwap;


C:\TADS\TADS\DPRMYLDHKDdlg.cpp(395) : error C2679: binary '=' : no
operator defined which takes a right-hand operand of type 'class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char>>' (or there is no acceptable conversion)

Can anyone tell me how to convert from string to CString?
Thanks,
A.
0
Comment
Question by:decornez
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
yonat earned 30 total points
ID: 1176923
Try:
    m_HkdRunTime = CashOrSwap.c_str();

For the reverse direction:
    CashOrSwap = (LPCTSTR)m_HkdRunTime;
0
 

Author Comment

by:decornez
ID: 1176924
It seems to get rid of the error message, but for some reason, my m_HkdRunTime variable which is attached to a dialiog box's edit box does not display anything !

Any idea why ?

Thanks,
Arnaud.
0
 
LVL 5

Expert Comment

by:yonat
ID: 1176925
Are you updating the display? You need to call UpdateData() after changing the value of m_HkdRunTime. (If you do this in OnInitDialog(), then UpdateData() already gets called by the framework.)

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:decornez
ID: 1176926
Yes, I do update the data but it does not work.

Anyway I guess that's another question later if I cannot fix it. In the meantime you fixed the error message I had, so well done and thanks for your help.

A.
0
 
LVL 5

Expert Comment

by:yonat
ID: 1176927
Hmmm. Maybe there's some memory management problem (though there shouldn't be). Just to be sure, try to do:

size_t strLen = CashOrSwap.length();
char* strBuf = new char[strLen+1];
memcpy(strBuf, CashOrSwap.data(), strLen);
strBuf[strLen] = '\0;'
m_HkdRunTime = strBuf;

And see if anything good comes out of it. If it turns out good, see what happens when you delete strBuf.
0
 

Author Comment

by:decornez
ID: 1176928
yonat,

I really appreciate your follow up on this question.
I have tried your suggestion but it still does not work.

Since it is probably not such an easy question, I have put it up with 40 points for grabs so that if you do find the solution you can be rewarded for your efforts. The heading of the question I have posted is: "Edit Box does not display output".

So hope to see you there.

Thanks,
A.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now