Installing and Using the Visual Studio IDE
You can get the “Community” version of Visual Studio free. The community version is very similar to the Enterprise edition; differences are listed here: https://www.visualstudio.com/vs/compare/. Note that in the rest of this document there are screenshots to help you. Sometimes these are just a portion of the entire application, in order to save space.
There is also a video to go along with this guide.
Downloading and Installing
If you’re using Windows 8.1 or Windows 10, go to https://visualstudio.microsoft.com/vs/community/ to find the Visual Studio Community page. Click the “Download Visual Studio” button.
If you’re still using Windows 7 or 8, I would suggest upgrading. If that’s not possible, go to https://visualstudio.microsoft.com/vs/older-downloads/ to find the Visual Studio Community 2013 page. Click the “Download Community 2013” button.
You’ll be downloading a web installer that’s around 1 MB. Run the application named “vs_Community” (there may be a long version number also) to start the installation process. This will in turn download somewhere around 5 GB to install the entire program, so make sure you have sufficient time, battery, etc. Choose the installation option of “Desktop development with C++”, and leave all the other options as defaults. After launching, you will probably have to log in to a hotmail or outlook account (my copy is already set up and no longer forces me to perform this step). If you need to find the menu option for this, it is under Help -> Register Product. After installing, you have to perform a one-time setup. Choose “Visual C++” as your default settings.
Visual Studio and getopt
The biggest problem with using Visual Studio with EECS 281 is that the IDE/compiler does not have the file getopt.h in its include folder, nor does a compiled version of the functions exist. You can overcome this by using two files: getopt.h and getopt.c (click links to download).
The getopt.c file is easier to use: simply put a copy in each project that needs it. When you turn in your project, do NOT make getopt.c part of your tarball (the Makefile that we give you should skip it).
The getopt.h file is a little more problematic. There are two approaches to solving this problem.
-
Easier but poor solution: Put
getopt.hinside your project folder, and#include "getopt.h"instead of<getopt.h>. When you pack up your project to test on CAEN or submit, you have to change your include statement to<getopt.h>. You should also NOT includegetopt.has part of your submission tarball. The big problem with this solution is that if you forget to change from double quotes to angle quotes, your project will fail to compile when you submit, and waste time (and possibly a submit for the day). -
More difficult but better solution: Put the
getopt.hfile inside one of the standard Visual Studio include folders. For Visual Studio 2022 Community, this folder is usually located in:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\includeIf you’re using a different version of VS (such as Community 2019), the location might be slightly different:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\VS\includeThis location is usually locked and can only be accessed if you are “Administrator”.
Type Windows-R (using the Windows key like a shift key, hold it down and type R, then release the Windows key). In the box that appears, type
explorerand hit Enter.Browse to your Downloads folder and copy the file
getopt.h. Then browse to the location shown above by starting at “This PC” (in the bottom left), and paste the file.
Creating Projects
The primary screen you see after starting Visual Studio should look similar to that shown below. The second time you open it, some of your previous projects will appear in the “Open recent” area. If the project you want is not there, click on “Open Project” (more on this later).

Click on “Create a new project” (in the bottom right) and you will see a window pop up. The default selections that we’re going to make will very likely not be selected the first time that you use it, but they will become the defaults afterward. For Visual Studio Community, choose the project type “Empty Project”.
To make things easier to find, we strongly suggest that you leave the box UNCHECKED that is labeled “Place solution and project in the same directory”. Type in a name for the new project, such as test, Hello, Project0, etc. You can also use the … button to select a new folder; for instance I created one called EECS281 in my Documents folder.

After you select “Create”, you will be inside the Visual Studio IDE with your newly created project opened. After you create the project, you need a place to put your source code! To do this, right-click on “Source Files” and you’ll get a popup menu opened from it. Hover over “Add” and another new menu opens. In this menu, click on “Existing Item” if you already have source code, or “New Item” to create a new project from scratch. The rest of this document will work on a new project with new code (the video shows how to use existing code).

To specify what type of file to add, under Visual C++, select the “Code” entry, then select “C++ File (.cpp)”. Type in the name of the source code file below. For instance, for this test project, you could type the filename Hello; the .cpp will be added automatically. One thing to be careful of is not to put any periods in the filename. If you do that, Visual Studio will not automatically append the .cpp file type, and then you won’t be able to compile.
If you already had source code files, you would copy them to the project folder before this, then choose “Add / Existing Item”. When you do this, make sure that your source code files are inside your project folder! If you have to browse around for them, say in a Downloads folder, you should first copy or move them to the project folder (outside of Visual Studio, such as Windows Explorer or the WSL).
To make editing easier, you should turn on line number display (if it’s not already on by default). To do that, choose the menu Tools -> Options, expand the Text Editor option (click the triangle to the left of it), then choose “All Languages”. Under Settings, select “Line numbers” and click OK.

To make sure that things are working, type in a simple “Hello, world” type program. That will let you get a little practice with the editor, make sure that you can build and run a project, etc. If you don’t like the font size, Control-mousewheel will increase/decrease the font size. For example:

Notice the “test.cpp*” tab above the code; that shows the name of the file you’re currently editing, and the asterisk means it has not been saved. You don’t need to save every file separately though! When you’re editing a large project with multiple files, every time you Build (compile), every file is saved automatically.
Building
Choose Build -> Build Solution from the menu, and keep an eye on the shortcut keys that are displayed, getting used to using those will save you time in the long run. After choosing this, look at the output window near the bottom; if it compiles correctly you’ll see output like that shown below. If not, you can scroll through any error messages and, if they’re from the compiler, double-click on them to take you directly to the offending line in the source code!

Even if it builds correctly, get in the habit of scrolling up to check for warnings (things like a type mismatch). When you’re ready, choose Debug -> Start Without Debugging to run the program. You should see a console window open up similar to the following.

If the font size is too small, right-click on the “C:\” box at the upper left, choose Properties -> Font, and change the size. When you’re done, DO NOT click on the “X” at the upper right, instead do what it says and press any key. If you do that, Visual Studio performs some memory checks (such as invalid pointers) that get skipped if you close it via the “X”. Your hello program probably doesn’t use pointers, but it’s best to get in the habit now of pressing any key.
What happens if your output window opens and then immediately closes before you can read it? This generally happens when you redirect input. There is a way to prevent this. Set a breakpoint on the “return 0” line of main() by either pressing F9 when you’re on that line, or left-clicking in the gray margin to the left of the line numbers. Then use Debug -> Start Debugging to start your project execution. You might also have to add a breakpoint to any line of code that calls exit().
Source Code Files
If you need to upload your files to CAEN, or download files to Visual Studio, you can look in the project folder on your computer. By default, these are created in the following location (but in this document and the video we changed the location):
C:\Users\<your-name>\Documents\Visual Studio 2017\Projects\
Rather than having multiple copies of your files, on your PC, on CAEN for compiling there, on a flash drive, etc., it would be better to keep them in one place. Consider using GitHub. Visual Studio is compatible with it! Here’s a video created by Microsoft about it.
Using Command-Line Parameters
After creating a project, you may want to pass command-line parameters when you run the program, such as flags, filenames, etc. To do this, right-click on the project name (in bold) inside of the Solution Explorer pane, choose Properties (the last option in the popup menu), then select Configuration Properties -> General -> Debugging. Choose the option on the right called “Command Arguments”; left-click on the empty place to the right and type in whatever you need. For example, for Project 0 you could type in:
-m nosize < sample-n.txt
Where sample-n.txt is the name of a text file inside of your project folder, that will be used as input. To create the input file, either use Notepad and Save As into the project folder, or use Windows Explorer to navigate to the project folder and right-click where there are no filenames to create a New -> Text Document. Put the input file(s) in the same folder as your .cpp files. For Visual Studio to redirect input files to cin, the file must be located inside of the project folder.

Opening a Project
If the project that you want to open has scrolled off your list of recently opened projects, select “Open Project”. This will open a file viewer, which forces you to know what to look for. Click on a folder name, then look for a file of type “Visual Studio Solution” and select that file:

Resetting Options
Sometimes it is possible to mistakenly click on things and lose access to certain portions of the IDE. For example, if you accidentally close the Solution Explorer that becomes the default setting for all projects. To get it back, click on View -> Solution Explorer. If you make too many changes that you don’t like, it is possible to reset the entire user interface to the default settings. To do this, select Tools -> Import and Export Settings -> Reset all settings.
If you’re still having trouble
Instead of trying to put the getopt.h file in a folder that requires admin access, you could instead put it in your repos folder. By default, this location is:
C:\Users\<your-name>\source\repos\
Just put the getopt.h in that folder, then modify EACH project that you create to tell Visual Studio to look in that location. The way to do is this to right-click on the project name (not the solution name, below I right-clicked on test which is shown in bold), and choose Properties (last line at the bottom):

After the Properties dialog box is visible, open up the C/C++ menu option (click on the arrow next to it), and edit the “Additional Include Directories” as shown below:
