命令'cin'和'cout'不起作用

Commands 'cin' and 'cout' not working

本文关键字:不起作用 cout cin 命令      更新时间:2023-10-16

我在Windows 8.1上安装了MinGW,以便用C++进行编码,我正试图使用Sublime Text 3运行我的代码。到目前为止,我是成功的,但我不能使用cincout。我知道我可以使用scanfprintf。但我可能还需要使用cincout。当我试图构建一个包含cincout的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