Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 998
Afzaal Ahmad Zeeshan Avatar asked Oct 21 '13 19:10

Afzaal Ahmad Zeeshan


People also ask

Can I use Visual Studio to compile C?

The Visual Studio build tools include a C compiler that you can use to create everything from basic console programs to full Windows Desktop applications, mobile apps, and more.

How do I use C code in Visual Studio?

After stopping the C file, go & click the File button at the top left corner of the Visual Studio Code Editor, and select the Settings via Preferences, as shown below image. After clicking the Settings, it shows the image below. In this image, select the extension button to set the settings for the C Compiler.


1 Answers

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.

like image 160
tomi.lee.jones Avatar answered Oct 16 '22 17:10

tomi.lee.jones