免费注册 查看新帖 |

Chinaunix

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

超菜问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-02-06 19:38 |只看该作者 |倒序浏览
小弟刚学VC,看到书上的第一个程序有一句:using namespace std;
请问大家是什么意思?(我在C++中没见过)

论坛徽章:
0
2 [报告]
发表于 2003-02-06 20:30 |只看该作者

超菜问题

随便找本C++书,好像都会有吧?

论坛徽章:
0
3 [报告]
发表于 2003-02-06 21:54 |只看该作者

超菜问题

使用名字空间吧
std是标准的
用了名字空间后
#include <iostream.h>; 就可以写成#include <iostream>;应该是这样的
应该是一种新的规范
具体什么用 我太菜了 体会不到

论坛徽章:
0
4 [报告]
发表于 2003-02-07 09:18 |只看该作者

超菜问题

using namespace std;

可以加快编译速度,对小程序没什么效果。
最好还是写上,养成良好习惯

我刚学C++。。。。。。大家互相帮助:)

98年以后都不用#include<iostream.h>;
新标准是:  
#include<iostream>;
using namespace std;

论坛徽章:
0
5 [报告]
发表于 2003-02-07 11:44 |只看该作者

超菜问题

错。
这个不是为了加快编译速度,而是为了方便协同开发而增加的关键字。
其中包括要对2各关键字的理解 namespace 和 using.
我也不是完全了解,因为我从来没有用过。我的理解是c++已经
有class对对象进行了包装,但是没有对以前用文件进行管理的
全局变量,公共函数进行包装。namespace用来完成这个任务。

下面是我从c++builder中截出的解释,英文好的可以帮助翻译一下。
我算然看的懂,但是让我给你讲出来就啰嗦的要死。

namespace
Category
C++-Specific Keywords

Description

Most nontrivial applications consist of more than one source file. The files can be authored and maintained by more than one developer. Eventually, the separate files are organized and linked to produce the final application. Traditionally, the file organization requires that all names that aren't encapsulated within a defined namespace (such as function or class body, or translation unit) must share the same global namespace. Therefore, multiple definitions of names discovered while linking separate modules require some way to distinguish each name. The solution to the problem of name clashes in the global scope is provided by the C++ namespace mechanism.

The namespace mechanism allows an application to be partitioned into a number of subsystems. Each subsystem can define and operate within its own scope. Each developer is free to introduce whatever identifiers are convenient within a subsystem without worrying about whether such identifiers are being used by someone else. The subsystem scope is known throughout the application by a unique identifier.

It only takes two steps to use C++ namespaces. The first is to uniquely identify a namespace with the keyword namespace. The second is to access the elements of an identified namespace by applying the using keyword.

using (declaration)
Category
C++-Specific Keywords
Description

You can access namespace members individually with the using-declaration syntax. When you make a using declaration, you add the declared identifier to the local namespace. The grammar is

   using-declaration:

          using :: unqualified-identifier;


Using declaration

If you want to use several (or all of) the members of a namespace, C++ provides an easy way to get access to the complete namespace. The using-directive specifies that all identifiers in a namespace are in scope at the point that the using-directive statement is made. The grammar for the using-directive is as follows.

   using-directive:

      using namespace  :: opt nested-name-specifier opt namespace-name;

The using-directive is transitive. That means that when you apply the using directive to a namespace that contains using directives within itself, you get access to those namespaces as well. For example, if you apply the using directive in your program, you also get namespaces A, ONE, and TWO.

   namespace A {

      using namespace ONE;  // This has been defined previously
      using namespace TWO;  // This also has been defined previously

      }

The using-directive does not add any identifiers to your local scope. Therefore, an identifier defined in more than one namespace won't be a problem until you actually attempt to use it. Local scope declarations take precedence by hiding all other similar declarations.

补充:
这个在c++老版本上没有(bc31)。gcc上不知道有没有,知道的请说一声。
新标准不一定就必须使用,如果你只编写windows下的程序估计没有问题。
如果要跨平台那么为了方便移植最好使用大家通用认可的标准。

论坛徽章:
0
6 [报告]
发表于 2003-02-07 11:56 |只看该作者

超菜问题

应该是要使用 STL 模板库吧, 有这些头文件吗? 比如
#include <list>;
#include <string>;
#include <vector>;
#include <algorithm>;

论坛徽章:
0
7 [报告]
发表于 2003-02-07 11:58 |只看该作者

超菜问题

其实他include的还是原来的 list.h string.h
只是处理的方法不一样。

论坛徽章:
0
8 [报告]
发表于 2003-02-07 12:29 |只看该作者

超菜问题

踢死牛  
偶懒得理你。。。。。。。。

论坛徽章:
0
9 [报告]
发表于 2003-02-07 18:11 |只看该作者

超菜问题

不会吧!
我们关系这么好,你这么一说,弄得我不知道该怎么办了。
Chinajiji 该用户已被删除
10 [报告]
发表于 2003-02-09 04:14 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP