sting用法1

# include <iostream>
# include <string>

using namespace std;

int main(){

    char pszName[20] = "张飞";
    char * pszName2 = "张飞";

    string strName("张飞");
    cout<<pszName<<endl;
    cout<<pszName2<<endl;
    cout<<strName<<endl; 

    string strName1 = "张飞";
    cout<<strName<<endl;

    //C字符串转换成C++ 
    const char *pszConstString = "Hello String!";
    string strFromConst(pszConstString); //复制 
    cout<<strFromConst<<endl;

    //复制pszConstString的前5个 
    string strPartialCopy(pszConstString,5); 
    cout<<strPartialCopy<<endl;

    //利用构造函数传递信息 
    string str2("Hello String");
    string str2Copy(str2);//复制 
    cout<<str2Copy<<endl; 


    // 初始化10个a
    string strRepeatChars(10,'a');
    cout<< strRepeatChars<<endl;
    return 0;
}  






你可能感兴趣的:(String)