No main.h when using quick actions

I’ve followed the video and used CTRL+ to make PlayGame a function from the loop but VS did not add the

#include “main.h”

and it automatically added the

void PlayGame();

on top of the main. Is this difference caused by an update or have I set up something wrongly?

EDIT: I’ve played 10 more seconds of the video and realised VS just saved me a few seconds of work.

1 Like

Yes! Same thing here! It seems that the newer version of VS actually adds the prototype directly, theres also the detail about reviewing the modified main.cpp before it is “commited” into the code,and then you can click Promote to Document.
Like this:

Edit: It doesn’t add the return; line, as noted in the course as necessary. Probably a good idea to add it.
Edit2: It seems the declaration of the function is done regardless of promoting to document, I think it is there just so you see the declaration and the definition of the function at the same time.


I have the same problem and just watched your video. So basically, there is no fix for it but to create the .h file manually?


You don’t want it, continue the video. Ben deletes it as it’s unwanted.

Thanks Dan.

I tried adding the return line, but that actually screwed up my program. It caused the game to stop after one guess and close out.

gives this:

while this:

gives this:

am I missing something?

You have to add the return line outside the loop, as the return breaks the loop it is in.

void PlayGame()
    constexpr int NUMBER_OF_TURNS = 5;
    for (int count = 1; count <= NUMBER_OF_TURNS; count++)
        cout << endl;

Think of it as you called a function to PlayGame and in the middle of running it the function actually returned a result, and said “I’m done, I did what I was supposed to do, bye” the rest of the program just kept going until the end of the program. But when you put it outside the loop the function will only return a result after all the fuss is done on the for loop. So the game goes on.

1 Like

That’s done it. Thanks I hadn’t even thought of that.

Learning so much so fast. Hope it sticks.

1 Like

So this is what I got instead what they show in the video when i use extract function, which if i’m looking at it seems to be just what you want by the end?

Yeah I think those of us with VS17 aren’t getting the main.h file generated with hash include. Good news is the teacher doesn’t keep his anyways.

Privacy & Terms