0

I'm trying to learn to program in C++ since I hardly know the language at the moment. I downloaded Visual Studio Express 2017 and made a very simple HelloWorld.cpp file, but I get the error as shown below.

I've checked the syntax multiple times, but I don't see an error in the code itself, which makes me believe there may have been a problem in the installation itself. However, since I am very new to VSE, I don't even know where to begin fixing this issue. If you could lend me a hand, that would be great.

The error message:

[3/24/2018 6:49:30 PM Error] System.ArgumentNullException: Value cannot be null.
Parameter name: solutionDirectory
   at Microsoft.VisualStudio.TestPlatform.ObjectModel.ValidateArg.NotNull[T](T arg, String parameterName)
   at Microsoft.VisualStudio.TestWindow.Controller.TestRunConfiguration..ctor(TestContainerConfigurationQuery testRunQuery, String resultsDirectory, String solutionDirectory, Boolean ignoreDiscovery, ILogger logger, Boolean keepAlive)
   at Microsoft.VisualStudio.TestWindow.Controller.RequestConfigurationFactory.CreateTestRunConfigurationBase(TestContainerConfigurationQuery query, Boolean ignoreDiscovery)
   at Microsoft.VisualStudio.TestWindow.Controller.RunAllOperation.CreateRunConfiguration()
   at Microsoft.VisualStudio.TestWindow.Controller.RunOperation.get_RunConfiguration()
   at Microsoft.VisualStudio.TestWindow.Controller.RunOperation.<RunTestsAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Controller.RunOperation.<ExecuteInternal>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.TestWindow.Controller.Operation.<ExecuteWithEvents>d__40.MoveNext()

The code itself, if you want to confirm there is nothing wrong with it:

// HelloWorld.cpp

#include <iostream>

int main()
{
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

enter image description here

2012ssohn
  • 159
  • 8
  • Can I give you an advice? If you are still learning syntax, use something like Codeblocks (download the version with the compiler). After that, you can go to something like Visual Studio or Eclipse CPP. That is my personal experience. Sometimes you are getting some error because of the IDE or something like that. It happens a lot with VS. – WillEnsaba Mar 24 '18 at 23:16
  • 2
    How did you set your project up? – BobMorane Mar 24 '18 at 23:17
  • 3
    You are missing a project. The Run button in the screenshot reads `Attach to process`. It should read `run`/`start` or `debug` – rollstuhlfahrer Mar 24 '18 at 23:21
  • The Output tab should read "Show Output from Build" not Tests. I expect you either did not create a project or picked the wrong type of project. – drescherjm Mar 24 '18 at 23:23
  • Be sure to restart MSVS and from Menu: `file->new->project->visual c++->win32->win32 console application -> finish` and paste the code build and run. Don't remove `#include "stdafx.h".` Because you should `local windows debugger` not `attach.` – Raindrop7 Mar 25 '18 at 00:08

1 Answers1

1

The problem is not with your code. The installation should be OK also. I believe you did not set up your C++ project correctly. See this tutorial, which explicits every steps on how to generate a valid C++ Hello World project in Visual Studio 2017.

BobMorane
  • 3,870
  • 3
  • 20
  • 42
  • Thank you! I followed the tutorial and it seems to work much better. I get the following [message](https://i.imgur.com/9lVtHXL.png) in the Debugger - should I worry about that? (Side note: The original tutorial I was referring to didn't have the `#include "stdafx.h"` line, what does that do?) – 2012ssohn Mar 25 '18 at 01:15
  • Good! [PDB files](https://msdn.microsoft.com/en-us/library/ms241613.aspx) are special files that are generated when you build so that you can match your executable with source files, and hence debug. It seems that you have not set your project so that PDB files are generated, and so debugging is not working. As for [`stdafx.h`](https://stackoverflow.com/questions/4726155/whats-the-use-for-stdafx-h-in-visual-studio), this is a Microsoft specific header, but you do not need it for your program. If you need more detail, I suggest you make separate questions. – BobMorane Mar 25 '18 at 02:26
  • BTW don't be afraid to look the web on Visual Studio, Microsoft has an excellent online documentation on the matter. – BobMorane Mar 25 '18 at 02:27