2017-05-03 52 views
2

我想用Visual Studio 2015編譯一小段C++代碼,當我包含iostream庫時,出現一些奇怪的編譯錯誤,任何人都可以幫我解決它嗎?如何使用iostream編譯C++代碼包括

這裏是我的代碼

#include "stdafx.h" 
#include <iostream> 

int main() 
{ 
    std::cout << "Somethig" << std::endl; 
    return 0; 
} 

這裏是我得到的錯誤,當我編譯這個

1>------ Build started: Project: ConsoleApplication3, Configuration: Debug Win32 ------ 
1> stdafx.cpp 
1> ConsoleApplication3.cpp 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(100): error C2737: 'std::is_same_v': 'constexpr' object must be initialized 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(100): error C2998: 'const bool std::is_same_v': cannot be a template definition 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(245): error C2737: 'std::is_integral_v': 'constexpr' object must be initialized 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(245): error C2998: 'const bool std::is_integral_v': cannot be a template definition 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(282): error C2737: 'std::is_floating_point_v': 'constexpr' object must be initialized 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(282): error C2998: 'const bool std::is_floating_point_v': cannot be a template definition 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(295): error C2737: 'std::is_arithmetic_v': 'constexpr' object must be initialized 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(295): error C2998: 'const bool std::is_arithmetic_v': cannot be a template definition 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstddef(697): error C2737: 'std::is_function_v': 'constexpr' object must be initialized 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstddef(697): error C2998: 'const bool std::is_function_v': cannot be a template definition 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(524): error C2275: '_To': illegal use of this type as an expression 
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(521): note: see declaration of '_To' 
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(526): note: see reference to class template instantiation 'std::is_assignable<_To,_From>' being compiled 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(524): error C2275: '_From': illegal use of this type as an expression 
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(522): note: see declaration of '_From' 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(524): error C3861: '__is_assignable': identifier not found 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(524): error C2975: '_Val': invalid template argument for 'std::integral_constant', expected compile-time constant expression 
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xtr1common(21): note: see declaration of '_Val' 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1245): error C2061: syntax error: identifier '__make_integer_seq' 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1249): error C2065: '_Vals': undeclared identifier 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1249): error C2975: '_Vals': invalid template argument for 'std::integer_sequence', expected compile-time constant expression 
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1190): note: see declaration of '_Vals' 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1252): error C2061: syntax error: identifier 'make_integer_sequence' 
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\type_traits(1261): error C2631: 'identity': a class or enum cannot be defined in an alias template 
1>c:\users\ugurku\documents\visual studio 2015\projects\consoleapplication3\consoleapplication3\stdafx.cpp : fatal error C1903: unable to recover from previous error(s); stopping compilation 
1> INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe' 
1>  Please choose the Technical Support command on the Visual C++ 
1>  Help menu, or open the Technical Support help file for more information 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

一切都有助於將appriciated。

+2

擺脫'#包括「stdafx.h」。 –

+0

ICE總是一個編譯器錯誤。您的安裝有問題。你是如何安裝VS2015的? –

+0

通常的方法,用visual studio安裝程序安裝它。 –

回答

0

好像這是一個關於我的Visual Studio安裝的問題,我只是重新安裝它,問題沒有了。

0

#include <cstdlib>

您應該重新安裝視覺工作室,因爲我覺得爲什麼你的代碼將無法編譯將是唯一的一點是,因爲你忘了庫頭

+0

我做過了,當我重新安裝演播室時,相同的代碼編譯 –

+0

@UğurKURT - 您是否嘗試過下載用於Windows 10的MinGW C++編譯器?我目前有這個。讓我們知道你是否決定這麼做。任何時候一個軟件都不適合你,你總是可以嘗試別的。 – User445555