'cout'不是'std'& 'cout'未在此范围中声明 [英] ‘cout’ is not a member of ‘std’ & ‘cout’ was not declared in this scope

查看:235
本文介绍了'cout'不是'std'& 'cout'未在此范围中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到有几个这样的重复,但没有一个为我工作到目前为止。
我试图在Ubuntu上使用g ++编译一个C ++非常简单的程序,但它给我的范围错误。

  #include< iostream> 
using namespace std;

int main()
{
cout< 你好,世界;
}

这会给我这个错误: >

  sudo g ++ -v test.c 
test.c:在函数'int main()':
test .c:7:3:错误:'cout'未在此范围内声明

定义范围许多其他帖子说,但是也没有工作,但给了我一个不同的错误:

  #include < iostream> 

int main()
{
std :: cout< 你好,世界;
}

产生错误:
$ b

  test.c:在函数'int main()':
test.c:6:3:error:'cout'is not std的成员

大多数在线建议建议using namespace std; include和std :: cout。
所以我试过所有3在一起,仍然没有运气:(

  #include< iostream> 
using namespace std;

int main()
{
std :: cout<<Hello world;
}

会出现错误

  test.c:在函数'int main()':
test.c:7:3:error:'cout'不是'std'的成员






我已经经历了几个论坛在线,但没有一个似乎为我工作(



这是更大问题的一部分,因为我的一个linux make不起作用。



Btw,我使用g ++而不是gcc作为一些帖子。






编辑1: p>

我将名称更改为.cpp,并且不使用sudo执行此处是详细输出:

  pranoy @ pranoyubuntu1210:〜/ Desktop / SIP / SIPp / sipp-3.3 $ g ++ -v test.cpp -o test 
使用内建规格
COLLECT_GCC = g ++
COLLECT_LTO_WRAPPER = / usr / lib / gcc / x86_64-linux-gnu / 4.7 / lto-wrapper
目标:x86_64-linux-gnu
配置为:../src/configure -v - with-pkgversion ='Ubuntu / Linaro 4.7.2-2ubuntu1'--with-bugurl = file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages = c,c ++,go, fortran,objc,obj-c ++ --prefix = / usr --program-suffix = -4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir = / usr / lib --without-included-gettext --enable-threads = posix --with-gxx-include-dir = / usr / include / c ++ / 4.7 --libdir = / usr / lib --enable-nls --with-sysroot = / --enable-clocale = gnu --enable-libstdcxx-debug --enable-libstdcxx-time = yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable- werror --with-arch-32 = i686 --with-tune = generic --enable-checking = release --build = x86_64-linux-gnu --host = x86_64-linux-gnu --target = x86_64-linux- gnu
线程模型:posix
gcc版本4.7.2(Ubuntu / Linaro 4.7.2-2ubuntu1)
COLLECT_GCC_OPTIONS =' - v''-o''test''-shared-libgcc ''-mtune = generic''-march = x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE测试。 cpp -quiet -dumpbase test.cpp -mtune = generic -march = x86-64 -auxbase test -version -fstack-protector -o /tmp/cczzibvL.s
GNU C ++(Ubuntu / Linaro 4.7.2-2ubuntu1 )由GNU C版本4.7.2,GMP版本5.0.2,MPFR版本3.1.0-p3,MPC版本0.9编译的版本4.7.2(x86_64-linux-gnu)

GGC启发式: -param ggc-min-expand = 100 --param ggc-min-heapsize = 131072
忽略不存在的目录/ usr / local / include / x86_64-linux-gnu
忽略不存在的目录/ usr /lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include
#include...搜索从这里开始:
#include< ...>搜索从这里开始:
/usr/include/c++/4.7
/usr/include/c++/4.7/x86_64-linux-gnu
/usr/include/c++/4.7/backward
/usr/lib/gcc/x86_64-linux-gnu/4.7/include
/ usr / local / include
/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
/ usr / include / x86_64-linux-gnu
/ usr / include
搜索列表的结尾。
GNU C版本4.7.2,GMP版本5.0.2,MPFR版本3.1编译的GNU C ++(Ubuntu / Linaro 4.7.2-2ubuntu1)版本4.7.2(x86_64-linux-gnu)
。 0-p3,MPC version 0.9
GGC启发式:--param ggc-min-expand = 100 --param ggc-min-heapsize = 131072
编译器可执行的校验和:521527ea42f0901bf839bcaad0cb13e6
test.cpp :在函数'int main()':
test.cpp:5:3:error:'cout'不是'std'的成员
$ b> $ p>

解决方案


$ b

听起来你没有为C ++环境安装所有必要的文件,或者有些东西不太对。尝试此操作:

  $ sudo apt-get remove g ++ libstdc ++  -  6.4.7-dev 
$ sudo apt-get安装build-essential g ++ - multilib

(运行 dpkg -l | grep libstdc ++ 来得到的libstdc的确切版本++如果上面的失败)


I realize that there are several duplicates like this but none of them have worked for me so far. I am trying to compile a C++ very simple program on Ubuntu using g++ but it is giving me scope errors.

#include <iostream>
using namespace std;

int main()
{
  cout << "Hello world";
}

This gives me this error:

sudo g++ -v test.c
test.c: In function ‘int main()’:
test.c:7:3: error: ‘cout’ was not declared in this scope

I also tried defining the scope as many other posts say, but that also didn't work, but gave me a different error:

#include <iostream>

int main()
{
  std::cout << "Hello world";
}

Gives error:

test.c: In function ‘int main()’:
test.c:6:3: error: ‘cout’ is not a member of ‘std’

Most of the suggestions online suggest "using namespace std;", "#include " and "std::cout". So I tried all 3 together, still no luck :(

#include <iostream>
using namespace std;

int main()
{
  std::cout << "Hello world";
}

gives error:

test.c: In function ‘int main()’:
test.c:7:3: error: ‘cout’ is not a member of ‘std’


I have gone through several forums online but none of them seem to work for me :(

This is a part of a bigger issue because of which one of my linux make doesn't work.

Btw, I am using g++ and not gcc as a few posts messed up.


EDIT 1:

I changed the name to .cpp, and execute without sudo. Here is the verbose output:

pranoy@pranoyubuntu1210:~/Desktop/SIP/SIPp/sipp-3.3$ g++ -v test.cpp -o test
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.2-2ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) 
COLLECT_GCC_OPTIONS='-v' '-o' 'test' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -march=x86-64 -auxbase test -version -fstack-protector -o /tmp/cczzibvL.s
GNU C++ (Ubuntu/Linaro 4.7.2-2ubuntu1) version 4.7.2 (x86_64-linux-gnu)
    compiled by GNU C version 4.7.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.7
 /usr/include/c++/4.7/x86_64-linux-gnu
 /usr/include/c++/4.7/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.7.2-2ubuntu1) version 4.7.2 (x86_64-linux-gnu)
    compiled by GNU C version 4.7.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 521527ea42f0901bf839bcaad0cb13e6
test.cpp: In function ‘int main()’:
test.cpp:5:3: error: ‘cout’ is not a member of ‘std’

解决方案

What you've written works absolutely fine on my Ubuntu system, with the same version of g++.

It sounds like you haven't installed all of the necessary files for the C++ environment, or something isn't quite right with it. Try this:

$ sudo apt-get remove g++ libstdc++-6.4.7-dev
$ sudo apt-get install build-essential g++-multilib

(Run dpkg -l | grep libstdc++ to get the exact version of libstdc++ if the above fails)

这篇关于'cout'不是'std'&amp; 'cout'未在此范围中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆