This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / forward a message from comp.lang.c++, so quiet here.Is there a way to find the size of memory allocated to a string. I don't
want to use strlen function. I want to implement it.
For eg.
char* string = new char[80];
cin>>string;
cout<<"Length of the string entered is :
"<<sizeof(string)/sizeof(char)<<endl;
The problem here is sizeof(string) functions returns 4(the size of char*),
but what i want is the size of memory allocated for variable string.
Is there a function to get this?
-bluelotus(时光漫步);
2003-6-17
{449}
(#1245509@0)
-
here it is:int sizeof_string(char *string)
{
char *p=string;
while( *p !=0x00 )
p++;
return(p-string);
}
-eagle_no1(瞎起哄);
2003-6-17
{117}
(#1245530@0)