<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 在這里總結一下string的用法 String是可變長字符串,使用的時候要包含string頭文件。 要想使用標準C++中string類,必須要包含 ~~~ #include <string>// 注意是<string>,不是<string.h>,帶.h的是C語言中的頭文件 using? std::string; using? std::wstring; 或 using namespace std; 下面你就可以使用string/wstring了,它們兩分別對應著char和wchar_t。 ~~~ 初始化: ~~~ ? ? ? ? string s1;???? //是一個空的string ??????? strings2(s1); ??????? strings3="hello";? //拷貝初始化 ??????? strings4=s3;??????? // 將s3的內容拷貝給s4 ??????? strings5(10,'c');?? //直接初始化,string中有十個c ??????? strings6("hello");? //s6中內容是hello ~~~ **對string讀寫操作:** ~~~ (2)??? string a;??//讀寫string對象 ?while(cin>>a) ?{ ?? ???cout<<a<<endl; ?} while(getline(cin,a)) ??????? ??? cout<<a<<endl; cout<<a<<endl;對于此類的操作,string對象對此操作也是返回運算符左側的運算對象作為其結果。即,可以實現級聯操作。 相當于,???????? cout<<s1<<s2<<s3<<endl; ??????????cin<<s1<<s2<<s3<<endl; (2)當我們遇到不知道具體數量的string時 ?? ????stringword; ??????? ??? while(cin>>word) ????????????????? cout<<word<<endl; ~~~ 只有當cin插入流遇到文件結束或者非法輸入時才結束。(例如空白字符,或者文件結束標志) (3)**關于string的對象的操作:** string s; ~~~ s.empty();?? //當string對象為空時,返回真,否則返回假 s.size();???? //返回S中字符的個數(但返回的類型并不是int 類型,而是size_t類型,一種無符號的類型) ~~~ 使用兩個等號的比較運算符時‘==’,當且僅當兩個string對象中字符一對一相等并且長度相等。 String對象可以直接相加 ~~~ string S1=”hello”; string S2=” C++”; String s3=s1+s2;?? //S3的內容是 “hello C++” ~~~ String 對象也能可字面值(字符串)進行相加 ~~~ String s1=”hello”; S1=s1+” C++”???? //s1 的結果仍然是hello C++ ~~~ (4)**關于string的一些操作函數** Isspace(c)?當c是空白字符時(空格回車 制表),返回真 tolower(c)??大寫轉小寫 toupper(c)??小寫轉大寫 對于處理string中的字符 我們有如下方法,我們以大小寫轉換為例 ~~~ stringstr3="a,b,c"; ??????? decltype(str3.size())i;????? 我們使用decltype()來獲取string中字符下標的類型 ??????? for(i=0;i<str3.size();i++) str3[i]=toupper(str3[i]); ??????? cout<<str3<<endl;? ?????string的 內容變為大寫 A B C ~~~ 我們還可以通過使用迭代器來遍歷字符,我們使用auto關鍵字,auto會自動根據初始值的類型來設定我們定義的變量 ~~~ //stringstr("zheng"); //for(autoi=str.begin();i!=str.end();i++)???? i的類型就是size_t類型 //????? *i=toupper(*i); //????? cout<<str<<endl;?? 輸出的結果是大寫? ZHANG ~~~ **string的特性描述:** ~~~ intcapacity()const;??? //返回當前容量(即string中不必增加內存即可存放的元素個數) intmax_size()const;??? //返回string對象中可存放的最大字符串的長度 intsize()const;??????? //返回當前字符串的大小 intlength()const;?????? //返回當前字符串的長度 boolempty()const;??????? //當前字符串是否為空 void resize(intlen,char c);//把字符串當前大小置為len,并用字符c填充不足的部 ~~~ 最后要介紹如何在Win32 應用程序中引用MFC中的部分類,例如CString。 1.在工程目錄下右鍵選擇"Properties”--->"Configuration Properties”--->“General”--->"Use of MFC"--->"Use MFC in a Static Library", 默認的是:"Use Standard Windows Libraries",
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看