久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      c++中string類的常用方法有哪些

      c++中string類的常用方法有哪些

      c++中string類的常用方法如下:

      1、獲取字符串長(zhǎng)度

        #include<cstdio> #include<iostream> #include<string> using namespace std; int main() {     string str1 = "hello";       int length = str1.length();     printf("調(diào)用str.length()函數(shù)獲取字符串長(zhǎng)度:%dnn",length );     return 0; }

      2、字符串連接

        #include<cstdio> #include<iostream> #include<string> using namespace std; int main() {     string str1 = "hello";     string str2="my girl!";     string str3="hello ";       string str4=str1+str2;     string str5=str3+str2;     cout<<"字符串str1+str2連接結(jié)果:"<<str4<<endl;     cout<<endl;     cout<<"字符串str3+str2連接結(jié)果:"<<str5<<endl;     return 0; }

      3、字符串比較

        #include<cstdio> #include<iostream> #include<string> using namespace std; int main() {     string str1 = "hello";     string str2="my girl!";     string str3="hello ";       if (str1 < str3)         cout << "字符串比較結(jié)果:" << "str1<str2" << endl;     cout << endl;     return 0; }

      4、字符串轉(zhuǎn)字符數(shù)組

        #include<cstdio> #include<iostream> #include<string> #include<cstring> using namespace std; int main() {     string str1 = "hello";     string str2="my girl!";     string str3="hello ";       char *d = new char[20];  //因?yàn)橄乱痪淠抢锊皇侵苯淤x值,所以指針類型可以不用const char *     strcpy(d, str3.c_str());  //c_str 取得C風(fēng)格的const char* 字符串     cout << "str3:" << c << endl;     cout << "d:" << d << endl;     str3 = "hahaha";     cout << "str3:" << c << endl;     cout << "d:" << d << endl;     return 0; }

      推薦教程:c語(yǔ)言教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)