wchar and stdout in VC11 - c++

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.

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.

Related

C++ Hello world keeps giving me errors in Visual Studio 2019

I'm just trying to print hello world using C++ but all I get is build errors. The error list shows 412 errors and they're mostly "Cannot open source file" followed by a file name that I haven't heard of.
It also says the WindowsSDKDir property is not defined and the solution I found was to repair visual studio when I looked up this problem. I completed repairing visual studio and I have the C++ selected in the workloads.
Even when I select "Console App" during initial set up it'll end up giving me the same errors even though that is supposed to set up a basic environment for Hello World.
My code is simply just to print out hello world.
#include <iostream>
void output();
int main()
{
output();
}
void output()
{
std::cout << "Hello World!" << std::endl;
}
So I just uninstalled Visual Studio completely and then reinstalled it. I realized I could have just modified it using the installer, but basically after selecting the C++ workload I made sure every box was selected on the right hand side. I don't know if I needed it all but I just installed everything to be sure and it finally worked.

Errors in C++ Hello World program

Installed c++ in visual studio 2019 some time ago and it worked perfectly. Today when I launched I got 490 errors. This is a screenshot of what a Hello World looks like: https://imgur.com/yxIs9Np
I am completely new to c++ so I dont know whats wrong, I have tried to search for the error but I could not find anything. I have tried to reinstall c++ in vs and updated vs to the newest version.
code:
#include <iostream>
int main() {
std::cout << "Hello World!\n";
}
its nothing wrong with the code, I think something is wrong with the librarys. For some reason I get 17 errors " cannot open file "[Some name].h" "
Reinstalled visual studio, this worked. The problem was that it dident include C:\Program Files (x86)\Windows Kits\10

Error code = 0x80070002 in visual studio c++

I just installed visual studio, (not new to coding) and I keep getting an error that goes like "error: unable to open file C:user...main.obj Error code = 0x80070002"
an Image of the error
this error shows up whenever there is something wrong with my code like for example if i do:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
everything runs normal, but if I make a mistake say:
#include <iostream>
int main()
{
std::cout std::cout << "Hello World!\n";
}
I get the error, it's so annoying I don't want to get that error every time there is something wrong with my code the error list bar is enough, what do I do ?
Could you please tell us what version of Visual Studio are you using?
If you are using vs2017 or later, I suggest you could try to use /DEBUG:FULL property in "Linker/Debugging/Generate Debug Info.
I suggest you could refer to the Doc:
When you specify /DEBUG with no additional options, the linker
defaults to /DEBUG:FULL for command line and make file builds, for
release builds in the Visual Studio IDE, and for both debug and
release builds in Visual Studio 2015 and earlier versions. Beginning
in Visual Studio 2017, the build system in the IDE defaults to
/DEBUG:FASTLINK when you specify the /DEBUG option for debug builds.
Other defaults are unchanged to maintain backward compatibility.
Rebuild the program in a different disk or reinstall the VS could be the final solution I think.

Simple Visual Studio console application does not start

I installed Visual Studio 2013 on my Windows 10 machine. To test the installation I wrote a simple program in C++:
#include <iostream>
using namespace std;
int main(){
cout << "Size of char is: " << sizeof(char);
cin.get();
return 0;
}
It's embarrassing to post such a simple code here but the problem is as follows. The build process runs without errors or warnings. But when I start the program via Debug-Button, Visual Studio freezes. I also tried starting the .exe in cmd. The result is a blinking cursor in an empty line with no further reaction from the console.
Can somebody tell me what's wrong? The Project Type in Visual Studio is empty visual c++ project.
Finally it works. As Peter M mentioned in his comment, the VS/Avast issue was the problem.

Visual Studio 2015 + libtcod - Unexpected exit

I am having an odd issue getting libtcod to work with Visual Studio 2015.
I have followed all the steps found on this blog post to get everything linked.
The problem is that during debugging or running it inside Visual Studio the application will always close at initRoot with exit code 1, no other information or errors.
Running the produced EXE outside of Visual Studio has no issues whatsoever - starts up and works as expected!
The only information I could find related to this was a forum post that turned ugly in 2012
I did make a modification to the blog post's code to include a setCustomFont as well, which did not change anything.
Does anyone have any ideas on what might be going on?
Code:
#include <cstdio>
#include "libtcod.hpp"
// Hide the console window
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
int main()
{
TCODConsole::setCustomFont("terminal12x12_gs_ro.png", TCOD_FONT_LAYOUT_ASCII_INROW | TCOD_FONT_TYPE_GRAYSCALE);
TCODConsole::initRoot(80, 50, "C++ libtcod tutorial");
TCODConsole::root->printEx(40, 25, TCOD_BKGND_NONE, TCOD_CENTER, "Hello world");
TCODConsole::flush();
TCODConsole::waitForKeypress(true);
return 0;
}
For anyone that stumbles upon this later, the above blog post is correct for setting up the vast majority of the application - if you run into the same issue I did (crashing / exiting in initRoot) make sure you have the terminal png in the source directory, this is what fixed it for me.