头文件的问题

kingapex1 2004-06-29 08:42:18
《 The C++ Programing Language 》第三章 有如下程序:

#include<iostream>
int main(){
std:cout<<"Hello Word!\n";
return 0
}

我在Vc++ 6.0 下编译如下错误:

f:\c++\teststring\teststring.cpp(3) : error C2065: 'cout' : undeclared identifier
f:\c++\teststring\teststring.cpp(3) : error C2297: '<<' : illegal, right operand has type 'char [13]'
f:\c++\teststring\teststring.cpp(4) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.

TestString.exe - 2 error(s), 1 warning(s)

记学C++的时候 是 #include<iostream.h>

改为#include<iostream.h> 通过

继续:

#include<iostream.h>
#include<string.h>

string name = "Hello Word";

int main(){
std:cout<<name<<"!\n";
return 0
}

还是有错误!

莫非这本书上面的程序是要在.net 下编译的?
菜鸟 莫笑:)

...全文
81 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
KaedeV 2004-06-29
  • 打赏
  • 举报
回复
呵呵 名字空间问题
kingapex1 2004-06-29
  • 打赏
  • 举报
回复
谢谢大家
回家研究 明天在请教 !
tllwong 2004-06-29
  • 打赏
  • 举报
回复
#include <iostream>
int main()
{
std::cout << "Hello World!\n" << std::endl;
retrun 0;
}
qiqi162002 2004-06-29
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
int main(){
cout<<"Hello Word!\n"; //有了using namespace std就不用std::了,标准库的                 // 东西可以直接用。
return 0 ;
}
qwertasdfg123 2004-06-29
  • 打赏
  • 举报
回复
使用
#include <iostream>
std::string name = "Hello Word";
kingapex1 2004-06-29
  • 打赏
  • 举报
回复
#include<iostream.h>
#include<string.h>

string name = "Hello Word";

int main(){
std::cout<<name<<"!\n";
return 0 ;
}

那这个也会通不过 好像没有 <string.h> ??
baizhj 2004-06-29
  • 打赏
  • 举报
回复
#include<iostream>
int main(){
std::cout<<"Hello Word!\n"; // : --> ::
return 0; // add ;
}
baojian88888 2004-06-29
  • 打赏
  • 举报
回复
哦,没看到,你的 std 后应该是两个冒号 ::
正确的:

#include<iostream>

int main()
{
std::cout<<"Hello Word!\n"; // 你少了一个冒号
return 0; // 你掉了一个分号
}
baojian88888 2004-06-29
  • 打赏
  • 举报
回复
1. 在你的include后增加一行 using namespace std; 试试

2. 你的 return 0 后掉了分号;

24,854

社区成员

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

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