string中含有 '/0'的使用

#include <iostream>
#include <cstring>
#include <string>
using namespace std;

int main ()
{
    char * cstr, *p;

    string str ("I love/0 you!",12);

    cout<<str<<":"<<str.size()<<endl;

    cstr = new char [str.size()+1];

    int length=str.copy(cstr, str.size(), 0);
    cstr[length]='/0';
    for(int i=0;i<length;i++)
        cout<<cstr[i];

    cout<<":"<<length<<endl;
    delete[] cstr;
    return 0;
}

你可能感兴趣的:(String,delete,include)