Using the "Unicode Character set" error, you should use the "use multibyte Character set"

Source: Internet
Author: User

"Void Atl::cstringt<basetype,stringtraits>::format (const wchar_t *,...)": cannot convert parameter 1 from "const char [29]"

The above problem should be used with multibyte character set

Case address, Baidu know quote

Problem:

"Void Atl::cstringt<basetype,stringtraits>::format (const wchar_t *,...)

cstring strdate,strtime;                          
systemtime St; Gets the local time
getlocaltime (&st);
strdate.format ("%4d-%2d-%2d", st.wyear,st.wmonth,st.wday);
strtime.format ("%4d:%2d:%2d" ", St.whour,st.wminute,st.wsecond);
getdlgitem (Idc_static_time)->setwindowtext (strdate + strTime);

settimer (1,1000,null);
return TRUE;

error C2664: "Void Atl::cstringt<basetype,stringtraits>::format ( Const wchar_t *,...) ": cannot convert parameter 1 from" const char [12] "to" Const wchar_t * "
1> Build failed.


answer:
You use a VC2005 or a higher version of it?
VC2005 and later versions use the Unicode character set by default, and CString is a wide character, that is, wchar_t, not char. You can write this:
Strdate.format (_t ("%4d-%2d-%2d"), St.wyear,st.wmonth,st.wday);
Strtime.format (_t ("%4d:%2d:%2d"), St.whour,st.wminute,st.wsecond);
To write the program later, define the string variable, do not use char*, and use tchar*. All string constants, not directly with "", but with _t (""). As an example:
tchar* str = _t ("Hello, World");

Of course, what I said above is in MFC. If you write a console program, you don't have to.



Using the "Unicode Character set" error, you should use the "use multibyte Character set"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.