代码无法运行,尽管语法正确

Code fails to run, despite proper syntax

本文关键字:语法 运行 代码      更新时间:2023-10-16

所以我试图在Visual Studio中运行这个,但它在输出控制台给了我几个错误:

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;

}

您没有阅读您正在使用的程序的文档。

#include "stdafx.h"必须先

改变头文件包含的顺序。预编译的头文件必须始终是源文件中的第一个非注释。