2

我正在尝试输入简单的“Hello World!” 代码,但 cout 和 endl 未定义。

#include<iostream>
#include "stdafx.h"
int main()
{
    std::cout << "Hello World!" << std::endl;
}

结果是错误:“'cout': is not a member of 'std', note: see declaration of 'std', 'cout': undeclared identifier”,和 endl 一样。请帮忙。

4

1 回答 1

1

您在 #include 语句中缺少一个空格: #include<iostream>

这是正确的方法: #include <iostream>

完整代码:

#include <iostream>
#include "stdafx.h"
int main()
{
    std::cout << "Hello World!" << std::endl;
}
于 2017-11-23T19:28:47.253 回答