免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2018 | 回复: 9
打印 上一主题 下一主题

[C++] 初学c++指教一下一个小程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-05-03 23:13 |只看该作者 |倒序浏览
#include <iostream>;
  #include <string>;

  int main()
  {
        string word ;
        while ( cin >;>; word )
            cout << "word read is: " << word <<"\n";
        cout << "OK: no more other words ro read: bye!\n";
        return 0;
  }

就这么小的阿,竟然在Linux用g++编译不过去,郁闷。提示:
input.cpp: In function `int main()':
input.cpp:6: error: `String' undeclared (first use this function)
input.cpp:6: error: (Each undeclared identifier is reported only once for each function it appears in.)
input.cpp:6: error: expected `;' before "word"
input.cpp:7: error: `cin' undeclared (first use this function)
input.cpp:7: error: `word' undeclared (first use this function)
input.cpp:8: error: `cout' undeclared (first use this function)

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-05-03 23:21 |只看该作者

初学c++指教一下一个小程序

#include <iostream>;
#include <string>;
using namespace std;
>;>;input.cpp:6: error: `String' undeclared (first use this function)
我没看到你代码里面有String。

论坛徽章:
0
3 [报告]
发表于 2005-05-03 23:34 |只看该作者

初学c++指教一下一个小程序

哦,贴错了阿。我贴的是我该的一点编译的错误。这个错误是如下:
input.cpp: In function `int main()':
input.cpp:6: error: `string' undeclared (first use this function)
input.cpp:6: error: (Each undeclared identifier is reported only once for each function it appears in.)
input.cpp:6: error: expected `;' before "word"
input.cpp:7: error: `cin' undeclared (first use this function)
input.cpp:7: error: `word' undeclared (first use this function)
input.cpp:8: error: `cout' undeclared (first use this function)

先谢了阿。

论坛徽章:
0
4 [报告]
发表于 2005-05-03 23:36 |只看该作者

初学c++指教一下一个小程序

缺了using namespace std;

论坛徽章:
0
5 [报告]
发表于 2005-05-04 00:00 |只看该作者

初学c++指教一下一个小程序

[quote]原帖由 "hmxxyy"]缺了using namespace std;[/quote 发表:

Thx.It's OK now.
It's always necessary to wirte "using namespace XX "??

论坛徽章:
0
6 [报告]
发表于 2005-05-04 00:26 |只看该作者

初学c++指教一下一个小程序

string 和 cin都属于std namespace
About the concept of namespce, please refer to the books.

It can not explained with serveral words here.

论坛徽章:
0
7 [报告]
发表于 2005-05-04 01:59 |只看该作者

初学c++指教一下一个小程序

Thank you very much!
I am now read Thinking in c++ 2th edition .Hope I can know more about c++.

论坛徽章:
0
8 [报告]
发表于 2005-05-04 16:59 |只看该作者

初学c++指教一下一个小程序

两个中国人为什么要用外语,想不通。。。其中一个还自称狭隘的民族主义者。

论坛徽章:
0
9 [报告]
发表于 2005-05-04 19:33 |只看该作者

初学c++指教一下一个小程序

[quote]原帖由 "tntlei"]两个中国人为什么要用外语,想不通。。。其中一个还自称狭隘的民族主义者。[/quote 发表:

呵呵呵

论坛徽章:
0
10 [报告]
发表于 2005-05-05 13:50 |只看该作者

初学c++指教一下一个小程序

[quote]原帖由 "tntlei"]两个中国人为什么要用外语,想不通。。。其中一个还自称狭隘的民族主义者。[/quote 发表:

所谓的“狭隘”是针对某些人来数,对我来说,就是对小日本。
别这样的"无知"了 ,中国人为什么不可以英文呢???
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP