我试图在PC上运行一个简单的hello世界,但是当我尝试对其进行编译时,我遇到了来自Cmath,stdio,stdlib的许多错误。我已经考虑过环境变量,但是我不知道它可能来自哪里。
我试图创建另一个项目并重新安装Visual Studio。
我在Windows 8.1上,安装了Windows SDK,并使用Visual Studio 2015社区。
我的问候世界代码:
#include "stdafx.h"
#include <iostream>
int main()
{
std::cout<<"hello world"<<std::endl;
return 0;
}
这是输出:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> stdafx.cpp
1>d:\visual studio\vc\include\stdio.h(295): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(295): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(297): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(297): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(297): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(304): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(304): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(304): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(307): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(307): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(307): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(316): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(316): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(316): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(318): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(318): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(318): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(321): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(321): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(321): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(322): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(322): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(322): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(345): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(345): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(345): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(349): warning C4003: not enough actual parameters for macro '__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_ARGLIST_EX'
1>d:\visual studio\vc\include\stdio.h(349): error C2146: syntax error: missing ';' before identifier '_vsnprintf'
1>d:\visual studio\vc\include\stdio.h(349): error C2143: syntax error: missing ',' before '*'
1>d:\visual studio\vc\include\stdio.h(349): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(349): error C2199: syntax error: found 'char (' at global scope (was a declaration intended?)
1>d:\visual studio\vc\include\stdio.h(349): error C2062: type 'char' unexpected
1>d:\visual studio\vc\include\stdio.h(352): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(352): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(352): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(357): warning C4003: not enough actual parameters for macro '__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_ARGLIST'
1>d:\visual studio\vc\include\stdio.h(357): error C2146: syntax error: missing ';' before identifier 'vsprintf'
1>d:\visual studio\vc\include\stdio.h(357): error C2143: syntax error: missing ',' before '*'
1>d:\visual studio\vc\include\stdio.h(357): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(357): error C2365: 'sprintf': redefinition; previous definition was 'data variable'
1> d:\visual studio\vc\include\stdio.h(357): note: see declaration of 'sprintf'
1>d:\visual studio\vc\include\stdio.h(390): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(390): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(390): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(393): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(393): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(393): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(402): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(402): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(402): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(457): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(457): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(457): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(461): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(461): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(461): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(468): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(468): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(468): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(470): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(470): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(470): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(474): warning C4003: not enough actual parameters for macro '__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_ARGLIST_EX'
1>d:\visual studio\vc\include\stdio.h(474): error C2146: syntax error: missing ';' before identifier '_vsnwprintf'
1>d:\visual studio\vc\include\stdio.h(474): error C2143: syntax error: missing ',' before '*'
1>d:\visual studio\vc\include\stdio.h(474): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(474): error C2199: syntax error: found 'wchar_t (' at global scope (was a declaration intended?)
1>d:\visual studio\vc\include\stdio.h(474): error C2062: type 'wchar_t' unexpected
1>d:\visual studio\vc\include\stdio.h(502): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(502): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(502): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(505): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(505): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(505): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(512): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(512): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(512): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(514): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(514): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(514): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(530): warning C4003: not enough actual parameters for macro '__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_ARGLIST_EX'
1>d:\visual studio\vc\include\stdio.h(530): error C2146: syntax error: missing ';' before identifier '_swprintf_s'
1>d:\visual studio\vc\include\stdio.h(530): error C2143: syntax error: missing ',' before '*'
1>d:\visual studio\vc\include\stdio.h(530): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(530): error C2146: syntax error: missing ';' before identifier 'vswprintf_s'
1>d:\visual studio\vc\include\stdio.h(530): error C2733: 'vswprintf_s': second C linkage of overloaded function not allowed
1> d:\visual studio\vc\include\stdio.h(461): note: see declaration of 'vswprintf_s'
1>d:\visual studio\vc\include\stdio.h(531): warning C4003: not enough actual parameters for macro '__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_2_ARGLIST_EX'
1>d:\visual studio\vc\include\stdio.h(531): error C2146: syntax error: missing ';' before identifier '__vswprintf_l'
1>d:\visual studio\vc\include\stdio.h(531): error C2143: syntax error: missing ',' before '*'
1>d:\visual studio\vc\include\stdio.h(531): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(531): error C2146: syntax error: missing ';' before identifier '_vswprintf_s_l'
1>d:\visual studio\vc\include\stdio.h(531): error C2733: '_vswprintf_s_l': second C linkage of overloaded function not allowed
1> d:\visual studio\vc\include\stdio.h(505): note: see declaration of '_vswprintf_s_l'
1>d:\visual studio\vc\include\swprintf.inl(40): error C3861: '_crt_va_start': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(42): error C3861: '_crt_va_end': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(64): error C3861: '_crt_va_start': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(66): error C3861: '_crt_va_end': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(88): error C3861: '_crt_va_start': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(89): error C3861: '_vswprintf': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(90): error C3861: '_crt_va_end': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(99): error C3861: '_vswprintf': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(108): error C3861: '_crt_va_start': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(109): error C2660: '__vswprintf_l': function does not take 4 arguments
1>d:\visual studio\vc\include\swprintf.inl(110): error C3861: '_crt_va_end': identifier not found
1>d:\visual studio\vc\include\swprintf.inl(119): error C2660: '__vswprintf_l': function does not take 4 arguments
1>d:\visual studio\vc\include\stdio.h(571): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(571): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(571): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(573): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(573): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(573): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(576): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(576): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(576): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(577): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(577): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(577): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(581): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(581): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(581): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\stdio.h(583): error C2144: syntax error: 'int' should be preceded by ';'
1>d:\visual studio\vc\include\stdio.h(583): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\stdio.h(583): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(968): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(968): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(968): error C2146: syntax error: missing ';' before identifier 'errno_t'
1>d:\visual studio\vc\include\wchar.h(986): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(986): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(986): error C2146: syntax error: missing ';' before identifier 'errno_t'
1>d:\visual studio\vc\include\wchar.h(1015): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(1015): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(1015): error C2146: syntax error: missing ';' before identifier 'errno_t'
1>d:\visual studio\vc\include\wchar.h(1022): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(1022): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(1022): error C2146: syntax error: missing ';' before identifier 'errno_t'
1>d:\visual studio\vc\include\wchar.h(1042): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(1042): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(1042): error C2146: syntax error: missing ';' before identifier 'errno_t'
1>d:\visual studio\vc\include\wchar.h(1053): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(1053): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(1053): error C2146: syntax error: missing ';' before identifier 'errno_t'
1>d:\visual studio\vc\include\wchar.h(1062): error C2144: syntax error: 'wchar_t' should be preceded by ';'
1>d:\visual studio\vc\include\wchar.h(1062): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(1062): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(1074): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(1074): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(1074): error C2146: syntax error: missing ';' before identifier 'errno_t'
1>d:\visual studio\vc\include\wchar.h(1078): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\visual studio\vc\include\wchar.h(1078): error C2086: 'int _CRTIMP_ALTERNATIVE': redefinition
1> d:\visual studio\vc\include\stdio.h(295): note: see declaration of '_CRTIMP_ALTERNATIVE'
1>d:\visual studio\vc\include\wchar.h(1078): fatal error C1003: error count exceeds 100; stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
最佳答案
您的代码看起来不错(除了在注释中提到的“stdafx.h”之外),因此这可能与项目设置有关。尝试创建一个新项目,但尝试创建一个“空项目”,该项目位于“Visual C++”和“常规”选项卡下。
关于c++ - 无法编译简单的Hello World C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34501733/