Solved

Conversion problem

Posted on 1998-11-04
6
221 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
Industry Leaders: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Grammars for C C++ and java 1 139
Printing the elements of a set declared inside a map in C++. 3 59
sorting efficency of sorting algorithm 30 132
print bytes of an integer 6 26
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

726 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