Solved

Conversion problem

Posted on 1998-11-04
6
209 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 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