#include<stdio.h>
#include<string>
#include<cstring>
using namespace std;
void main()
{
string ss("hello world");
string pp("test string");
int i=0;
char * nn = (char * )&ss[0];
char * mm = (char * )&pp[0];
int xx = mm-nn;
printf("%d\n",xx);
while(i<300)
{
if(nn[i]==0)
{
printf("%c",'@');
i++;
}
else
printf("%c",nn[i++]);
}
}
在VC6.0运行可以看出string包含的字符串是以0结尾的
#include<string>
#include<cstring>
using namespace std;
void main()
{
string ss("hello world");
string pp("test string");
int i=0;
char * nn = (char * )&ss[0];
char * mm = (char * )&pp[0];
int xx = mm-nn;
printf("%d\n",xx);
while(i<300)
{
if(nn[i]==0)
{
printf("%c",'@');
i++;
}
else
printf("%c",nn[i++]);
}
}
在VC6.0运行可以看出string包含的字符串是以0结尾的