#include <string>
#include <string>
//using namespace std; //1,不要这句也能通过,这是为什么?
int main()
{
char *p = NULL;
return 0;
}
2,找到NULL的定义后:
.#ifdef __cplusplus //如果没有定义__cplusplus
#define NULL 0 //则定义NULL 为 0
#else //否则定义NULL为((void *)0)
#define NULL ((void *)0)
#endif
什么时候要定义:__cplusplus
问题点数:50、回复次数:12Top
1 楼qfpcn(ξ幽灵ξ)回复于 2002-04-17 14:36:43 得分 5
这是系统做的事,不用你管。Top
2 楼yg_xh(果皮)回复于 2002-04-17 14:49:16 得分 10
1.这是c++新的库为了兼容原有的函数库所以提供了两个版本的函数,为了区别就把新的库定义在名字空间std下,可以这样用std::xxx,所以你的程序可以通过;
2.不知道Top
3 楼linxiao()回复于 2002-04-17 14:55:07 得分 0
yg_xh(果皮):
不要using namespace std;我的程序也能通过啊?
我是<string>不是<string.h>Top
4 楼jimmyxu()回复于 2002-04-17 15:14:03 得分 15
There is a file named "string", which can be found by VC. In fact it is a convention to C++, and string.h is the standard or older header file of ANSI C. And C++ has rewritten it using string, without suffix .h, to tell you their difference. To C++, the standard string.h is renamed to cstring, that is, when you include cstring, in fact you include the string.h. Of course, the string.h has still existed, especially to ANSI C user. So you can write what you wrote above and realize what you want. But, the best practice is to using cstring in C++ program, and use string.h in C program.
As of the statement
using namespace std;
it is another practice, which will be allowed to use function defined in namespace std, that is to use
std::xxx
Nothing else.Top
5 楼jimmyxu()回复于 2002-04-17 15:16:50 得分 5
Sorry for my mistaken.
If you use using directive using, you can use cout, cin etc without appending std::; else you should add!
Top
6 楼mickeyfirst(黑梦)回复于 2002-04-17 15:17:22 得分 5
__cplusplus是用来判断是不是符合C++规范。Top
7 楼programCat()回复于 2002-04-17 16:13:06 得分 5
你又没有声明一个string类,当然能通过了啊。
你试着写一句
string s; 看看
保证你通不过。当你使用string的时候,你必须得加using namespace std;Top
8 楼linxiao()回复于 2002-04-18 11:48:56 得分 0
programcat():
你的意思是 #include <string> 没有派上用场?在这个程序中是可有可无的?但是你把 #include <string> 去掉,那个程序就编译通不过了
Top
9 楼programCat()回复于 2002-04-24 09:13:23 得分 5
那是因为你去掉<string>之后,NULL没有定义。
你可以自己定义
加上const int NULL=0;这句Top
10 楼linxiao()回复于 2002-05-11 14:44:13 得分 0
我以为下面两句是要一起用的:
#include <string>
using namespace std;
但这道题中,确可以不要using namespace std; 这是为什么?
Top
11 楼linxiao()回复于 2002-05-13 10:00:02 得分 0
????Top
12 楼linxiao()回复于 2002-05-29 15:52:01 得分 0
我以为下面两句是要一起用的:
#include <string >
using namespace std;
但这道题中,确可以不要using namespace std; 这是为什么?
Top




