maxven

<cstring> 创建详解

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{

    //1. 字符串的创建
    cout<<"第一:字符串的创建!\n\n";
    string a(4,'a');
    cout<<"1.以 a 为原字符 4单位大小\n\n";
    cout<<"string a(4,'a');\ncout<<a<<endl;\n";
    cout<<a<<endl<<endl;

    cout<<"2.任意大小的字符串\n\n";
    cout<<"string b(\"bbbbbb\");\ncout<<b<<endl;\n";
    string b("bbbbbb");
    cout<<b<<endl<<endl;

    cout<<"3.把某一字符串的某一部分\n(0位置开始4个长度)给c\n\n";
    cout<<"string c(a,0,4) ;\ncout<<c<<endl;\n";
    string c(a,0,4) ;
    cout<<c<<endl<<endl;

    cout<<"4. 10长度原长度不足补*;\n\n";
    cout<<"c.resize(10,'*');\ncout<<c<<endl;\n";
    c.resize(10,'*');
    cout<<c<<endl<<endl;

    system("pause");
    system("cls");
    return 0;
}