Afzaal Ahmad Zeeshan Afzaal Ahmad Zeeshan - 25 days ago 12
C++ Question

How to use Visual Studio C++ Compiler?

I recently installed Visual Studio 2013. I can create a new project (Visual C++), but the error I have to come across is that I cannot run the app. Here is the code that I'm trying to run on Visual Studio 2013.

#include <iostream>
using namespace std;

int main() {
cout << "Hello World";
return 0;
}


I am sure this code would run, and will output hello world, but in Visual Studio it gives me issues, saying:


Values cannot be null,

Parameter name: solutionDirectory.


What am I missing here?

Here is an image for this:

enter image description here

Answer

In Visual Studio, you can't just open a .cpp file and expect it to run. You must create a project first, or open the .cpp in some existing project.

In your case, there is no project, so there is no project to build.

Go to File --> New --> Project --> Visual C++ --> Win32 Console Application. You can uncheck "create a directory for solution". On the next page, be sure to check "Empty project".

Then, You can add .cpp files you created outside the Visual Studio by right clicking in the Solution explorer on folder icon "Source" and Add->Existing Item.

Obviously You can create new .cpp this way too (Add --> New). The .cpp file will be created in your project directory.

Then you can press ctrl+F5 to compile without debugging and can see output on console window.

Comments