简体   繁体   English

Visual C ++中的Hello World程序给出错误

[英]Hello World program in Visual C++ giving errror

I've installed visual studio 2012. I wrote a simple "hello world" program in a new project. 我已经安装了visual studio 2012.我在一个新项目中编写了一个简单的“hello world”程序。 Here's the code: 这是代码:

#include <iostream>
int _main()
{
    cout<<"Hello world";
    cin.get();
    return 0;
}

When the use of precompiled headers was on, I got error related to stdafx.h so I turned precompiled headers off and removed #include stdafx.h . 当使用预编译头文件时,我得到了与stdafx.h相关的错误,因此我关闭了预编译头文件并删除了#include stdafx.h

Now I get these strange error messages: 现在我收到这些奇怪的错误消息:

  • error C2018: unknown character '0x3' 错误C2018:未知字符'0x3'
  • error C2018: unknown character '0x4' 错误C2018:未知字符'0x4'
  • error C2018: unknown character '0x40' 错误C2018:未知字符'0x40'
  • error C2146: syntax error : missing ';' 错误C2146:语法错误:缺少';' before identifier 'ÿÿ¸' 在标识符'ÿÿ¸'之前
  • error C4430: missing type specifier - int assumed. 错误C4430:缺少类型说明符 - 假定为int。 Note: C++ does not support default-int 注意:C ++不支持default-int

And many more similar errors causing the build to fail. 还有更多类似的错误导致构建失败。 The error is given by cl.exe to each and every line of the code. cl.exe将错误提供给代码的每一行。

Things I have tried so far: 到目前为止我尝试过的事情:

  • created an empty project with just 1 .cpp file including that code; 用一个包含该代码的.cpp文件创建了一个空项目;
  • tried using std::cout ; 尝试使用std::cout ;
  • tried using int main() instead of int _main() ; 尝试使用int main()而不是int _main() ;
  • tried using namespace std ; 尝试using namespace std ;
  • tried the same things on Visual Studio 2010. 在Visual Studio 2010上尝试过相同的东西。
  1. Coding a consoleapplication in Viusal Studio and removing the include of the precompiled header gives you an error. 在Viusal Studio中编写控制台应用程序并删除预编译头文件的包含会给您带来错误。

  2. Look at your Linker-Properties (rightclick your project, select Properties and then select Linker - System). 查看链接器属性(右键单击您的项目,选择“属性”,然后选择“链接器 - 系统”)。 Be sure that you selected the SUBSYSTEM Console. 确保选择了SUBSYSTEM控制台。 Under Linker - Advanced you find your entry point. 在链接器 - 高级下,您可以找到您的入口点。 Be sure that your entry point = the name your main int. 确保您的入口点=您的主要int的名称。

  3. Maybe look at this: visual c++ 2010 errors importing User32.dll into 64bit win7 也许看看这个: visual c ++ 2010错误导入User32.dll到64位win7

Guys I realized a strange thing. 伙计们,我意识到了一件奇怪的事。 When I open VS and build for the first time, it builds successfully, but if I rebuild, it gives error. 当我第一次打开VS并构建时,它会成功构建,但如果我重建,则会出错。 So each time I make a change in the code and compile, it gives the same errors. 因此,每次我对代码进行更改并进行编译时,都会产生相同的错误。 But if I close VS and open again and try, it works. 但是,如果我关闭VS并再次打开并尝试,它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM