使用cout要加那些头文件?怎么不能编译?

flairy 2003-05-11 07:35:58
VC6.0, console application.

source code:
#include <iostream.h>
/* ---------- main ---------- */

int main (int argc, char* argv[])
{
const char *audioFileName= argv[1];



long int Nsamp = 0;
long int Nchan = 0;
float Sfreq =0;


int Nreq = 2;
float Fbuff[1024] = {0};
int Ndata=0;

cout<<"samples"<<endl;
// long offs = 0;
return 0;

}

/////////end

--------------------Configuration: Audiorw - Win32 Debug--------------------
Compiling...
Audiorw.c
g:\xrsu\i2r\audiorw\audiorw.c(43) : error C2065: 'cout' : undeclared identifier
g:\xrsu\i2r\audiorw\audiorw.c(43) : error C2297: '<<' : illegal, right operand has type 'char [8]'
g:\xrsu\i2r\audiorw\audiorw.c(43) : error C2065: 'endl' : undeclared identifier
Error executing cl.exe.

Audiorw.obj - 3 error(s), 0 warning(s)
...全文
4378 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gchhua 2003-05-11
  • 打赏
  • 举报
回复
cout是给c++用的,c++是c的超集.不要把c和c++搞混。
变量必须在前面申明,在c中。在c++中不需要.
flairy 2003-05-11
  • 打赏
  • 举报
回复
我决定全部用cpp,
继续问题:
1) cout 是不是给c++用的,不是c.
2) 又见一个奇怪的,

...
printf("samples");
long xx=0;
...又编译出错。(c语言,不是c++)
问在c语言里,是不是声明变量一定得在前面,不不记得有这种规定,呢是为什么呢?

wheagle 2003-05-11
  • 打赏
  • 举报
回复
对亚
我也没错阿
呵呵
flairy 2003-05-11
  • 打赏
  • 举报
回复
另外需要声明,
原文件是.c, 不是 c++
还有我是先appwizard一个empty console application, 这时不能编译。

1)如果是cpp, 可以
#include <iostream>
using namespace std ;解决。 可以简单解释一下为什么吗?
动物男孩 2003-05-11
  • 打赏
  • 举报
回复
把库文件改成
#include <iostream>
using namespace std ;
fiveyes 2003-05-11
  • 打赏
  • 举报
回复
我把你的程序复制->粘贴到我的VC6里面,编译,0错误,0警告。

我原封没动哟。
orcale 2003-05-11
  • 打赏
  • 举报
回复
加上using namespace std;

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧