【问题标题】:Code fails to run, despite proper syntax [duplicate]尽管语法正确,但代码无法运行 [重复]
【发布时间】:2016-10-02 18:34:47
【问题描述】:

所以我试图在 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;


}

【问题讨论】:

    标签: c++


    【解决方案1】:

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

    #include "stdafx.h" 必须首先

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2021-03-25
        • 2017-05-25
        • 1970-01-01
        • 1970-01-01
        • 2018-07-21
        • 2013-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多