开发者_Go百科General>Character Set." />
开发者

using unicode character set in VS 2008 project settings

开发者 https://www.devze.com 2023-01-15 05:29 出处:网络
In a project i need to set \"use unicode character set\" for Configuration Properties>开发者_Go百科General>Character Set.

In a project i need to set "use unicode character set" for Configuration Properties>开发者_Go百科General>Character Set.

On compiling the project, error c2664 is returned on this code:

char Filename[25] = {0}; 
GetLocalTime(&st); 
sprintf(Filename,TEXT("C:\\CpmMicr%02d%02d%04d.log"), st.wDay,st.wMonth,st.wYear);

When I change the character set configuration to "Not set" or "Multi-byte character set" project compiles without any errors.

Please suggest me on what should be done to fix this issue.

Thanks for any potential suggestions.

Lakshmi.


It is because you use the TEXT macro. That automatically puts an L before a string literal if you compile with _UNICODE defined. That blows up because you use sprintf(), a non-Unicode function. It wants a char*, not a wchar_t*.

There are three basic solutions here:

  1. Remove the TEXT macro
  2. Use TCHAR and the corresponding string functions consistently
  3. Use Unicode declarations in your code, wchar_t[] and swprintf().

No real point in 2, there is no mainstream operating system left that isn't native Unicode.


extremely hard to give an exact fix without code (please post relevant part), but likely you are trying to assign a char* to a wchar* or vice-versa. For example

std::basic_string< wchar_t > someString( "test" ); //C2664 here

should be

std::basic_string< wchar_t > someString( L"test" );

edit: the problem in your code is that you use the TEXT macro so in a unicode build that will be a wide char, sprintf takes const char* though. I have no idea why it used to work in previous versions of VS? Either use wsprintf and change Filename to be a wide char, or get rid of the TEXT macro.

0

精彩评论

暂无评论...
验证码 换一张
取 消