wchar and stdout in VC11

3

I've found a weird issue with outputting wide chars in Visual Studio 2012 which I've narrowed down to the following code.

#include <cstdio>
int main()
{
  fputws(L"Hello World\n", stdout); // Throws Access Violation exception
}

When compiling this with Visual C++ 2012 it throws an "Unhandled exception", "Access violation reading location 0x00000064", somewhere inside fputws.

What I'm using to compile is with is the CLI version, just to rule out any settings in the IDE. I am opening the Visual Studio Command Prompt and using the following:

cl test.cpp

When using Visual Studio 2008 or Visual Studio 2010 it works well, writing out "Hello World".

But when using Visual Studio 2012, it crashes with the above mentioned error.

I have a hard time believing it's a compiler issue but rather something that's changed between the different versions of C++.

Another (funny) thing is that if I output a normal char first, like the code snippet below, it works just fine. So what I think is that it is an issue with uninitialized streams?

#include <cstdio>
int main()
{
  fputs("", stdout);
  fputws(L"Hello World\n", stdout); // Now this works.
}

Anyone got any ideas?

Edit:

The following, similar, functions works fine in VS2012:

std::wcout << L"Hello world" << std::endl;
wprintf(L"Hello world\n");
_putws(L"Hello\n", stdout);
putwchar(L'H');

Edit 2: Just filed a bug report to microsoft.

c++
visual-studio-2012
asked on Stack Overflow Nov 28, 2012 by Mats Fredriksson • edited Nov 28, 2012 by Mats Fredriksson

1 Answer

1

I had this problem on a RTM VS2012 but didn't on VS2012 Update 1. After installing Update 1 on the problem system the error disappeared. Thanks to Mats for reporting this.

answered on Stack Overflow Feb 15, 2013 by wRAR

User contributions licensed under CC BY-SA 3.0