Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:18:26+00:00 2026-06-12T00:18:26+00:00

i want to convert CString to const char*, i used that const char* cstr

  • 0

i want to convert CString to const char*, i used that const char* cstr = (LPCTSTR)CString; but it doesn’t compile,so how to do that, or how to convert CString to double, i used this method _tstof but it returns 0 when i passed a CString to it, so i want to convert CString to const char* inorder to pass the converted value to the method atof(), here’s an example:

int nTokenPos=0;
CString leftDigit,rightDigit;
double firstNum,secondNum;

if(dialog->myValue.Find('X')!=-1){
CString resToken = dialog->myValue.Tokenize(_T("X"), nTokenPos);
leftDigit=resToken;
OutputDebugString(leftDigit);
while(!resToken.IsEmpty())
{
   resToken = dialog->myValue.Tokenize(_T("X"), nTokenPos);
   rightDigit=resToken;
   rightDigit+="\n";
  //OutputDebugString(rightDigit);
}
 firstNum= _tstof(leftDigit);
 secondNum=_tstof(rightDigit);
 OutputDebugString(leftDigit);
 OutputDebugString(rightDigit);
 TRACE( "First_Number %d\n",firstNum); --->OutPuts ZERO
 TRACE( "\nSecond_Number %d\n",secondNum); --->OutPuts ZERO
//MathFuncs::MyMathFuncs::Multiply(firstNum,secondNum);
 TRACE( "The result %d\n",MathFuncs::MyMathFuncs::Multiply(firstNum,secondNum));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:18:28+00:00Added an answer on June 12, 2026 at 12:18 am

    This line

    const char* cstr = (LPCTSTR)CString;
    

    doesn’t compile because I guess you are building an UNICODE build of your project and therefore _T expands to a 2-byte character (a wide character).

    To make this conversion working you could use the ATL macros. Like:

    USES_CONVERSION;
    const char* cstr = T2A((LPCTSTR)CString);
    

    However, this is not really related to your initial problem as you are using anyways _tstof() which handles the _T issues for you.

    [Edited]:

    The mistake is somewhere else. The format string of the TRACE is not using the wright placeholder for a float/double. Instead of %d use %f:

    CString leftDigit = _T("12.5");
    double  firstNum = _tstof(leftDigit);
    TRACE(_T("%f\n"), firstNum);
    

    I tried this and got 12.50000000 printed in the Output pane of VS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert a column of numbers to numeric, but there are certain
I want to convert CString to string. (Yup. I know what am I doing.
I want to convert a list object into a string and insert this string
I want to convert an iplimage to a cv::mat (not CvMat). With this code
i want convert this c++ code in C#: RECT rcCurrent; ::GetWindowRect ( hwndChild, &rcCurrent
this jquery code works fine for me in jquery format. I want convert this
I have a string to convert, string = apple and want to put that
I want convert an int into 2 bytes representing that int. Probably must use
I am new to Python and want convert this small JavaScript code to Python.
Want to convert decimal to binary but am getting some bugs. I am now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.