2016-10-02 3 views
-2

그래서 내가 비주얼 스튜디오에서이 작업을 실행하기 위해 노력하고있어하지만 나에게 출력 콘솔에서 몇 가지 오류 제공 :코드는 올바른 구문에도 불구하고, 실행되지

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 

내 코드는 다음과 같다 :

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

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

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

    return 0; 


} 

답변

1

사용중인 프로그램에 대한 설명서를 읽지 않았습니다.

#include "stdafx.h"의 첫 번째이어야합니다.

+0

감사합니다. 몰랐다. –

0

헤더 파일 포함 순서를 변경하십시오. 사전 컴파일 된 헤더 포함은 항상 소스 파일의 첫 번째 주석이 아니어야합니다.

관련 문제