could someone tell me how to calculate the size of a string constant?Thanks . The following is my source code which contain few bugs in it.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s="hello world";
int *ptr;
int i=0;
int length;
while((*ptr)!=' \0')
{
ptr=s;
i++;
}
length=i;
cout<<"the length of string is"<<length<<"c haracters"<<end l;
return 0;
}
can someone debug it for me?thanks!
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s="hello world";
int *ptr;
int i=0;
int length;
while((*ptr)!=' \0')
{
ptr=s;
i++;
}
length=i;
cout<<"the length of string is"<<length<<"c haracters"<<end l;
return 0;
}
can someone debug it for me?thanks!
Comment