string中含有 '/0'的使用

来源:互联网 发布:开源php 编辑:程序博客网 时间:2024/06/10 13:18

#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;
}

原创粉丝点击