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
Solved

Conversion problem

Posted on 1998-11-04
6
218 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
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 how to clear a vector as well as how to detect empty vectors in C++.

839 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