i cant get this simple code working

im like really new and im watching this tutorial and im copying his code his code worked just fine but mine says that 'cout': is not a member of 'std' and i dont understand it and dont know how to fix it can someone help

//This is my first C++ Program!!
#include <iostream>
#include "pch.h"
int main() {
std::cout << "Ham Sandwich!\n";
return 0;
}
Hi, please check the content of pch.h. There is no reason why this code should not work, so the problem must be in there. Try removing that include and see if it compiles: if it does, you have your answer.
Hello r0k33,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

It makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



I believe that #include "pch.h" has to go first.

1
2
3
4
5
6
7
8
9
#include "pch.h"
#include <iostream>

int main()
{
    std::cout << "Ham Sandwich!\n";

    return 0;
}

Give this version a try and I will try the same with your code.

Hope that helps,

Andy
Last edited on
Hello r0k33,

As I suspected the #include "pch.h" has to be the first include.

When your finished letting VS create for you it is better to create an empty project and code it your self.

If you click where it says Create new Project in the window that appears, it should say "New Project in the upper left conor. For me, on the left side it says "installed -> Visual C++". In the middle box it says:

Windows Console Application
Empty Project
Windows Desktop Application

Choose the "Empty Project". Then at the bottom enter a "Name" and change the location if needed.

When VS is finished with what it needs to do the screen will be empty except for the basic outline of VS.

At this you will have to add any files you need to the project. I usually use the short cut keys of "Ctrl + Shift + A" to do this. This brings up the window "Add New Item with three choices:

C++ File (.cpp)
Header File (.h)
C++ Class


Normally you would choose the (.cpp) or (.h), which I change to (.hpp). After choosing the type of file enter a name for the file and press Enter.

Somewhere along the edge of the VS window you should find a tab called "Solution Explorer". Click on this tab and at the bottom of the tree it will say "Source Files". If needed click on the empty triangle to make it solid and expand what is below it. Then double click on the file name to open it in the edit window.

You can also start by going to the menu under "Project -> Add new Item and follow the above instructions.

This way you do not need the "precompiled header file (.pch)", but you will have to code the header files that you need for the program.

Any questions let me know.

Hope that helps,

Andy
Topic archived. No new replies allowed.