高手进来看一下吧!

来源:百度知道 编辑:UC知道 时间:2024/06/14 12:37:22
这到链表时遇到的一个问题。关于动态内存分配
p=(struct STOCK2*)malloc(sizeof(struct STOCK2));
上面这个是正确的。
下面这个是我想出来的,用在里面都有错误,相请教一下是哪里的问题,麻烦高手解释一下!用到下面这两个时都会有同样的错误。
p=new strlen(struct STOCK2);还有strlen和sizeof都需要什么头文件?
p= new sizeof(struct STKCK2);
Compiling...
链表2.cpp
链表2.cpp(15) : error C2061: syntax error : identifier 'strlen'
链表2.cpp(33) : error C2143: syntax error : missing ';' before '}'
';' before '}'
链表2.cpp(33) : error C2143: syntax error : missing ';' before '}'
链表2.cpp(33) : error C2143: syntax error : missing ';' before '}'
链表2.cpp(33) : error C2143: syntax error : missing ';' before '}'
链表2.cpp(33) : error C2143: syntax error : missing ';' before '}'
链表2.cpp(33) : error C2143: syntax error : missing ';' before '}'
\链表2.cpp(33) : error C2143: syntax error : missing ';' before '}'

syntax error 意思是语法错误
p=new strlen(struct STOCK2);
strlen(),是求一个字符串的长度的返回值是int型,不能像这样用,
要用strlen(),要包进来头文件string;#include<string>
大致用法:
string s;
int a=s.strlen();
sizeof()一般不需要直接包含什么了。