[英]Commands 'cin' and 'cout' not working
我在Windows 8.1上安裝了MinGW以C ++編寫代碼,並且試圖使用Sublime Text 3運行我的代碼。到目前為止,我已經成功了,但是我無法使用cin
和cout
。 我知道我可以改用scanf
和printf
。 但是我可能還需要使用cin
和cout
。 當我嘗試構建包含cin
或cout
的C ++代碼時,它給出了編譯時錯誤。 讓我們看一下產生這種錯誤的一段代碼:
#include "iostream"
#include "cstdio"
using namespace std;
int main()
{
int n;
std::cin >> n;
std::cout << n;
}
我的機器上出現的錯誤是:( 注意 :我的機器上已安裝WinGHCi以使用Haskell)
Info: resolving std::cin by linking to __imp___ZSt3cin (auto-import)
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-importc:/program files (x86)/haskell platform/2013.2.0.0/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.)
[Finished in 1.4s]
請幫助我找出問題所在。 我故意不想使用IDE。
注意,一般建議是使用<iostream>
而不是"iostream"
。 在這方面,使用<iostream>
會在編譯相同代碼時產生以下錯誤(用"iostream"
和"cstdio"
替換為<iostream>
和<cstdio>
):
Info: resolving std::cin by linking to __imp___ZSt3cin (auto-import)
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-importc:/program files (x86)/haskell platform/2013.2.0.0/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.)
[Finished in 1.8s]
在使用時,通常會引發以下類型或錯誤:
headers with version x
----------------------
lib with version y
因此,請檢查此。
如果您使用的編譯器的版本為4.6.3,但使用的標頭為4.6(出於任何原因),則會出現此類錯誤。
有用的命令:
which g++ #locate where is your compiler (generally /usr/bin/g++)
g++ --version #get compiler's version
find / -name iostream | grep c++ #find where're your includes
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.