-2

So i'm trying to run this in Visual Studio but it gives me several errors in the output console:

1>------ Build started: Project: ConsoleApplication1, Configuration: Release     x64 ------
1>  stdafx.cpp
1>  ConsoleApplication1.cpp
1>ConsoleApplication1.cpp(6): error C2039: 'cout': is not a member of 'std'
1>  predefined C++ types (compiler internal)(209): note: see declaration of 'std'
1>ConsoleApplication1.cpp(6): error C2065: 'cout': undeclared identifier
1>ConsoleApplication1.cpp(6): warning C4554: '<<': check operator precedence for possible error; use parentheses to clarify precedence
1>ConsoleApplication1.cpp(6): error C2039: 'endl': is not a member of 'std'
1>  predefined C++ types (compiler internal)(209): note: see declaration of 'std'
1>ConsoleApplication1.cpp(6): error C2065: 'endl': undeclared identifier

My code is as follows:

#include <iostream>
#include "stdafx.h"

void test(int x, int y)
{
    std::cout << x + y << std::endl;

}
int main()
{
    test(1, 2);

    return 0;


}
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055

2 Answers2

1

You didn't read the documentation for the program you're using.

#include "stdafx.h" must come first.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

Change the order of the header file inclusions. The precompiled header inclusion must always be the first non-comment in your source files.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621