我注意到有几个这样的重复项,但是至今为止他们都没有为我工作。 我想在Ubuntu上用g编译C非常简单的程序,但是范围错了。 “cout”不是“std”的成员,并且未在此范围内声明“cout”
#包含
using namespace std;
int main () )
{
计数' hello world ';
}
这给了我这个错误:
sudo g -v test.c
test.c: In function ‘int main ()’:
test.c :733603:错误:‘cout’wasnotdeclaredinthisscope
我也试图定义范围。 很多其他的职位都在说,虽然也没有工作,但是犯了不同的错误:
#包含
int main () )
{
std:cout 'Hello world ';
}
出现错误:
test.c: In function ‘int main ()’:
test.c :633603:错误:“cout”isnotamemberof“STD”
大多数在线建议使用“命名空间标准”、“#包含”和“std : cout”。 所以我尝试了所有的三个,但还没有运气: (
#包含
using namespace std;
int main () )
{
std:cout 'Hello world ';
}
发生了错误:
test.c: In function ‘int main ()’:
test.c :733603:错误:“cout”isnotamemberof“STD”
我经历过一些在线论坛,但是他们为了工作需要我的: (
这是更大的问题。 因为这是我的Linux制作不起作用的部分之一
顺便说一下,我把g而不是gcc作为几个帖子失败了。
编辑1 :
我修改的. cpp没有sudo执行的名称。 以下是详细的输出。
[ email protected ] :~/desktop/sip/sipp/sipp-3.3 $ g-vt est.CPP-o test
使用构建模式。
COLLECT_GCC=g
collect _ LTO _ wrapper=/usr/lib/gcc/x86 _ 64-Linux-GNU/4.7/LTO-wrapper
Target: x86_64-linux-gnu
配置with :/src/configure-v-- with-pkg version=' Ubuntu/Lina ro4.7.2-2Ubuntu1'-- with-bug URL obj-c--prefix=/usr-- program-suffix=-- 4.7-- enable-shared-- enable-linker-build-id-- with-system Li B- without-incled=/usr/include/c/4.7-- enable-clocale=GNU-- enable-libstdc xx-debug-- enable-libstdc xx-time=yes-- enable-GNU-unique EC king=release-- build=x86 _ 64-Linux-GNU-- Linux-- GNU
Thread model: posix
GC version4.7.2(Ubuntu/Lina ro4.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/C1 plus-quiet-v-imultiarchx 86 _ 64-Linux-GNU-d _ GNU _ sou sou sou rch
Ubuntu/Lina ro4.7.2-2Ubuntu1) version4.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
GC heuristics :---- param ggc-min-expand=100---- param ggc-min-heapsize=131072
ignoringnonexistentdirectory '/usr/local/include/x86 _ 64-Linux-GNU '
ignoringnonexistentdirectory '/usr/lib/gcc/x86 _ 64-Linux-GNU/4.7//./x86 _ 64-Linux-GNU/inu
# include ' . ' searchstartshere :
# include . searchstartshere :
/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
搜索列表结束。
Ubuntu/Lina ro4.7.2-2Ubuntu1) version4.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
GC heuristics :---- param ggc-min-expand=100---- param ggc-min-heapsize=131072
compilerexecutablechecksum :521527 ea 42 f 0901 BF 839 bcaad0CB 13e 6
test.CPP : in function‘int main’:
test.CPP :533603: error :“cout”isnotamemberof“STD”
2013-03-12
Pranoy C
7
为什么需要“sudo”来执行g? 文件扩展名必须是“. cpp”而不是“. c”吗?
2013-03-12 11:12:25
6
重命名源文件,并以".cpp "结尾,为" g "提供正确的线索。
2013-03-12 11:12:56
3
无法再现. -
2013-03-12 11:13:49