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

  • SEARCH
  • Home
  • 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 3631428
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:23:45+00:00 2026-05-19T00:23:45+00:00

I have a program in which I need to use the Format(); function to

  • 0

I have a program in which I need to use the Format(); function to combine a string literal and a int into a CString variable. I have tried several different ways of doing this, the code for them is here:

// declare variables used
CString _CString;
int _int;

// try to use format function with string literal
_CString.Format("text",_int); 

// try to use format function with C-Style cast
_CString.Format((wchar_t)"text",_int);

// try to use format function with static_cast 
_CString.Format(static_cast<wchar_t>("text"),_int);

The first one returns error C2664: ‘void ATL::CStringT::Format(const wchar_t *,…)’ : cannot convert parameter 1 from ‘const char [33]’ to ‘const wchar_t *’

For the second, there is no error but the text appears in Chinese characters.

The third one returns error C2440: ‘static_cast’ : cannot convert from ‘const char [33]’ to ‘wchar_t’

Any ideas for converting CStrings to wchar_t *s?
Thanks

  • 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-05-19T00:23:46+00:00Added an answer on May 19, 2026 at 12:23 am

    The problem is that you’re performing a UNICODE build (which is fine), so the

    _CString.Format(); 
    

    function i expecting the first parameter to be a wide character string. You need to use the L"" syntax to form a wide-character string literal:

    _CString.Format(L"text",_int); 
    

    Of course, you’ll need a specifier to actually get the int variable formatted into the CString:

    _CString.Format(L"text: %d",_int); 
    

    If you include the tchar.h header, you can use Microsoft’s macros to make the string literal wide-character or regular-old-character (otherwise known as ANSI) depending on whether you’re building UNICODE or not:

    _CString.Format(_T("text: %d)",_int); 
    

    but I’d say that unless you’re planning to support legacy stuff that’ll require ANSI support, I probably wouldn’t bother with the tchar.h stuff.

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

Sidebar

Related Questions

I have a program in which I need to store a Class object into
Just a quick question here. I have a program in which I need to
I need to make the program which have one form that contains PNG image
As a part of my program I use: int ret = vprintf (format, args);
I have a program in which I need to apply a 2-dimensional texture (simple
I have a database of 29 excel sheets which i need to use in
I have a program which creates JButtons which are then added to a JPanel
I have a program which dynamically generates a GUI. I don't know how many
I have a program which outputs a pair of words surrounded by spaces on
I have a program which prints a multi-page document. The first page is pre-printed

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.