Visual Studio 2012 C ++ Hello World-iostream无法正常工作 [英] visual studio 2012 c++ hello world - iostream not working
问题描述
我在Visual Studio 2012上遇到问题.我还使用山姆一天一次自学C ++,第7版".
I have an issue with Visual Studio's 2012. I am also using "Sams Teach Yourself C++ in One Hour a day, 7th edition".
在使用google查找C ++的最佳"编译器之后,Visual Studios似乎是首选工具.
After using google to find the "best" compilers for C++, Visual Studios seemed to be the tool of choice.
因此,我下载并安装了Visual Studios2012.这本书的第一节课是(并通过转到文件>新建>项目> Visual C ++> Win32>控制台应用程序,告诉我将其作为控制台应用程序运行)
So I downloaded and installed Visual Studios 2012. The very first lesson in the book is (and tells me to run it as a console app by going to File > New > Project >Visual C++ > Win32 > Console Application )
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
这根本不起作用.它会输出类似以下内容的错误消息:
which doesnt work, at all. it outputs an error message similiar to the following:
1> c:\ users \ nik \ documents \ visual studio 2012 \ projects \ consoleapplication4 \ consoleapplication4 \ consoleapplication4.cpp(8): 错误C2065:"Hello":未声明的标识符 1>正在生成代码... ===========构建:0成功,1失败,0最新,跳过0 =========="
1>c:\users\nik\documents\visual studio 2012\projects\consoleapplication4\consoleapplication4\consoleapplication4.cpp(8): error C2065: '"Hello' : undeclared identifier 1> Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========="
(有更多的行与第一行相似,但相当长)
(there is more lines similiar to the first, but its rather long)
但是,在Google上谷歌搜索并观看视频后,以下代码有效(使用文件>新建>项目> Visual C ++>常规>空项目)
However, after googling and watching a video on youtube the following code works (using File > New > Project >Visual C++ > General > Empty Project )
#include <iostream>
#include "conio.h"
using namespace std;
int main() {
cout << "Hello Nik" << endl;
_getch();
return 0;
}
Visual Studio 2012是否具有C ++编译器?还是只是有一个可视化的c ++编译器(如果这甚至是问题,我认为可能的唯一原因是我可以看到Visual C ++的模板,但自己看不到c ++的模板...)还是我需要下载Visual Studio Express?下载本机c ++ ??
Does Visual Studio's 2012 have a C++ compiler? or does it just have a visual c++ compiler (if thats even the issue, only reason I think it could be is I can see templates for Visual C++ but none for c++ by itself...) or do I need to download Visual Studio Express to download native c++ ??
任何帮助都将不胜感激,因为我在这里感到有些不适...
Any help would be greatly appreciated as I am feeling some-what out of my depth here...
谢谢.
推荐答案
除了憎水剂,您可能需要在项目属性中禁用预编译头.
在VS2012中默认情况下将它们打开.如果您不熟悉预编译的标头,请关闭它们.
They are turned on by default in VS2012. If you are not familiar with precompiled headers turn them off.
- 右键单击项目(不是解决方案)
- 点击属性.
- 展开配置属性"
- 展开"C/C ++"
- 选择预编译头"
- 将预编译头"设置为不使用预编译头"
有关预编译标头和Wikipedia上stdafx.h文件的更多信息
这篇关于Visual Studio 2012 C ++ Hello World-iostream无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!