Simple Visual Studio console application does not start - c++

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.

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

Visual Studio 2013: Redirecting console output to Visual Studio Output Window

I am used to Eclipse CDT where the output of a program (using cout) is written to the "Console" window inside Eclipse.
Now I switched to Visual Studio 2013. When creating a simple C++ "Console Application" like
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
cout << "hello world" << endl; cin.get(); return 0;
}
the application is "run in the Dos console", i.e. when I press "Run" Visual Studio opens a small Dos window and runs the program from there. As a result, the system input and output has to be done over the Dos window as well.
My question is the following: Is it somehow possible to redirect the input and output to the Visual Studio Output window (or any other perspective/view inside Visual Studio)? I am just getting annoyed by the fact there is no integrated console...
So basically what I want to achieve is to see the "hello world" output in the "Output" Window of Visual Studio. Is this somehow possible?
Thanks
The most common way of doing that is to use OutputDebugString(str);

fatal error C1083: Cannot open include file: 'iostream': No such file or directory

I've reinstalled Visual Studio 2010 Professional several times to try to get it to work.
I had to uninstall Visual Studio 2012 Professional because it wasn't compiling something we did in class.
I completely uninstalled everything including SQL Server..
I went to VC/include and the iostream header file is not there.
#include <iostream>
int main () {
cout << "hello";
system ("PAUSE");
return 0;
}
This is all I'm trying to do because nothing else is working.
It's really driving me crazy because I need to get it working so that I can do my project!!!
Every time I do; new project => empty project => add an item to source =>.cpp
I'm running windows 8.
It just says Error cannot open source file
Also, error cout identifier is undefined....
I'm wondering if I should do a system restore?
Or if I should just completely reinstall windows 8 from my recovery media?
One problem is that you did not include the namespace std.
This is what your code should look like:
#include <iostream>
using namespace std;
int main (void) {
cout << "hello" << endl;
system("pause");
return 0;
}
or you could have done something like this: std::cout << "Hello" << std::endl;
This may be a problem because you did not set your environment to C++. This is how you do it:
Go to Tools > Import and Export settings. If you cannot find it, just search for it in Quick Search
Then go to reset all settings.
Then simply select "Visual C++"
Restart.
That should do the trick. If it does not, you might consider re-installing Visual C++ itself. For VS 2012. If that does not work, then re-install the program.
if it is problem with visual studio 2012, install this update.

wchar and stdout in VC11

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.