1

I have to do a programming project for an optimisation class, that has to be written in C or C++. So I'm trying to figure out Visual Studio 2015. I created a blank project, and opened a new C++ file, where I have the following:

#include <iostream>

int main()
{
    cout >> "Hello World!/n";
    cin.get();
    return 0;
}

When I run it, I get a large blank white popup, and nothing else happens, even if I hit various key on the keyboard or wait for several minutes. It looks like this:

Screenshot 1

If I close the large popup, nothing happens. What Visual Studio refers to as output from build looks like this:

1>------ Deploy started: Project: LinearProgramming, Configuration: Debug Win32 ------
1>Updating the layout...
1>Deployment complete (157ms). Full package name: "53acc796-5708-4314-9034-f2a1f840a4f4_1.0.0.0_x86__eazt3av84y7ym"
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

Could anyone please explain to me what's going on? How can I create a simple C++ project in Visual Studio 2015 and run it?

user141592
  • 111
  • 1
  • 3

3 Answers3

2

I believe you selected the "Blank App(Universal Windows)" project template, which is like a Microsoft store application. What you probably want is the "Win32 Console Application" template, which creates an application without its own window (and uses the console for I/O).

melak47
  • 4,772
  • 2
  • 26
  • 37
2

This is how I create a Win32 Console Application.

  1. Go to File->New->Project...
  2. Select Visual C++->Win32->Win32 Console Application and name the project.
  3. In the Win32 Application Wizard press the Next > button and be sure Console application and Empty project are selected, and then hit the finish button.
  4. In the Solution Explorer right click on Source Files and select Add->New Item...
  5. Select the C++ File (.cpp), name it, and hit the Add button.
  6. After you change the >> to << add the code above and it should run.
RitterS
  • 44
  • 5
2

The quick answer is to hit ctrl-f5 to open the console. After running your script and showing your output it waits for you to hit a key before closing the console.

I eventually found the answer to the question which can be seen at How to keep the console window open in Visual C++?

Altimus Prime
  • 2,207
  • 2
  • 27
  • 46