【发布时间】:2018-08-31 14:44:19
【问题描述】:
所以我对 C++ 完全是个菜鸟,我正在尝试为作业制作一个简单的“Hello world”程序。我的代码如下:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
cout<<"hello world!";
return 0;
}
出于某种原因,VS2017 在cout 处抛出一个错误,说它是未定义的。我已经阅读了一些关于此的旧帖子并添加到#include "stdafx.h 以查看是否可以按照旧建议解决它,但它继续给我错误。有什么想法吗?
编辑:
又是一个完整的菜鸟,但是当我搜索它时会出现多个版本的 stdafx.h,这看起来像“主要”版本:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently
#pragma once
#ifndef STRICT
#define STRICT
#endif
#include "targetver.h"
[!if SERVICE_APP]
#define _ATL_FREE_THREADED
[!else]
#define _ATL_APARTMENT_THREADED
[!endif]
#define _ATL_NO_AUTOMATIC_NAMESPACE
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
[!if PREVIEW_HANDLER || THUMBNAIL_HANDLER || SEARCH_HANDLER]
#ifdef _MANAGED
#error File type handlers cannot be built as managed assemblies. Set the Common Language Runtime options to no CLR support in project properties.
#endif
#ifndef _UNICODE
#error File type handlers must be built Unicode. Set the Character Set option to Unicode in project properties.
#endif
#define SHARED_HANDLERS
[!endif]
[!if SUPPORT_MFC]
#include <afxwin.h>
#include <afxext.h>
#include <afxole.h>
#include <afxodlgs.h>
#include <afxrich.h>
#include <afxhtml.h>
#include <afxcview.h>
#include <afxwinappex.h>
#include <afxframewndex.h>
#include <afxmdiframewndex.h>
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
[!endif]
[!if SUPPORT_COMPLUS]
#include <comsvcs.h>
[!endif]
#define ATL_NO_ASSERT_ON_DESTROY_NONEXISTENT_WINDOW
#include "resource.h"
#include <atlbase.h>
#include <atlcom.h>
#include <atlctl.h>
【问题讨论】:
-
奇怪。写信给我
std::cout。 -
您的安装完全损坏,或者您正在做的事情与您告诉我们的完全不同。这段代码应该可以毫无问题地编译。
-
呸。再次开始创建“控制台应用程序”。你似乎引入了各种 ATL 框架的东西。
-
你应该构建没有预编译的头文件(又名
stdafx.h)。恕我直言,他们在学习简单程序时不值得麻烦。当您的程序变得庞大时,请考虑使用预编译的标头。创建项目时,搜索所有选项并取消选中预编译的标头(只是说不)。 -
@RudyVelthuis -- “默认情况下没有设置” -- 是的,微软会教坏习惯以将人们锁定在他们的工具中。
标签: c++ visual-studio stl visual-studio-2017 cout