Solved

Conversion problem

Posted on 1998-11-04
6
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 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