基本的c程序不是在Ubuntu中编译的可信的
Basic c program not compiling in Ubuntu trusty
恭敬的问候,
这个基本的C程序不能在Ubuntu trusty 14.04.1 LTS中编译。编译行是 gcc array.c -std=c99(循环的最后一个选项(。我应该使用 ?是否有适用于 c(而不是 c++(的 iostream?
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(void)
{
int array[8];
for(int x=0;x<8;x++)
{
std::cin>>array[x];
}
for(int x=0;x<8;x++)
{
std::cout<<array[x];
}
return 0;
}
我收到的错误消息是
array.c:3:3: error: unknown type name ‘using’
using namespace std;
^
array.c:3:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘std’
using namespace std;
^
array.c: In function ‘main’:
array.c:9:9: error: expected expression before ‘:’ token
std::cin>>array[x];
^
array.c:13:5: error: duplicate label ‘std’
std::cout<<array[x];
^
array.c:9:5: note: previous definition of ‘std’ was here
std::cin>>array[x];
^
array.c:13:9: error: expected expression before ‘:’ token
std::cout<<array[x];
^
谢谢
这不是一个C程序,它是一个C++程序。将您的文件重命名为 array.cpp
和/或使用 g++
而不是 gcc
,不,C 中没有 iostream
这样的东西。
程序的第一个非 C 部分是
using namespace std;
C 中没有namespace
s。
第二部分是
std:cin>>array[x];
它有两点问题,首先为什么要using namespace std;
,然后std::cin
如果你在C++中使用using namespace
,这意味着它在省略时会在该命名空间中查找,其次这也是C++具体的。C 中没有流运算符。
您包含了stdio.h
因此您必须使用 fgets 或类似的函数。对于输出 printf 系列
相关文章:
- 在 Ubuntu 18.04 上编译 GLSL 着色器时"不支持 GLSL 3.30"?
- 在 Ubuntu 中编译 SuiteSparse,在安装 CHOLMOD 时中断
- 如何在 Ubuntu 上编译 OpenGL 项目?
- 在 ubuntu 焦点上编译虚幻引擎 4.25 时出错
- 在 Ubuntu 16.04 LTS 上使用 c++ 编译问题?
- 编译问题与 Ubuntu Linux
- Ubuntu 下的 Cmake 和 Intel IPP 的编译问题
- 在Linux/Ubuntu中编译openCV应用程序时,如何解决未定义的引用cv:..?
- 如何解决我在 Ubuntu 19.04 下使用 GLFW 时遇到的这个编译问题?
- wxWebView在Ubuntu上的编译问题
- 如何在Ubuntu中使用Visual Studio代码编译C++代码
- 在 Ubuntu 18.04 上,我编译的 cpp 可执行文件找不到 VTK7 依赖项
- 在 Xubuntu 19.04 中编译 c++ 是否应该与在 Ubuntu 18.04 中编译 c++ 不同
- 针对 ubuntu 和 Mac 编译的差异
- G++ 编译:在 Ubuntu 18.04 上对 'ATL_<...>' 的未定义引用
- cmake cuda在Windows上单独的编译静态LIB链接错误,但在Ubuntu上没有
- 加密蛋白使编译问题Ubuntu
- Open AL 的函数在 ubuntu 中使用 g++ 编译时给出未定义引用的错误
- 拥有LLVM IR库如何从Ubuntu将其交叉编译到iOS,Android,Windows和Mac?
- C++ 在 minGW-W64 g++ 中编译的代码不能使用 Ubuntu g++ 编译