<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # C++ 程序:查找字符串中元音,輔音,數字和空格的數量 > 原文: [https://www.programiz.com/cpp-programming/examples/vowel-consonant-frequency-string](https://www.programiz.com/cpp-programming/examples/vowel-consonant-frequency-string) 要理解此示例,您應該了解以下 [C++ 編程](/cpp-programming "C++ tutorial")主題: * [C++ 數組](/cpp-programming/arrays) * [C++ 字符串](/cpp-programming/strings) * * * * * * ## 示例 1:C 樣式的字符串 該程序從用戶那里獲取 C 風格的字符串,并計算元音,輔音,數字和空格的數量。 ```cpp #include <iostream> using namespace std; int main() { char line[150]; int vowels, consonants, digits, spaces; vowels = consonants = digits = spaces = 0; cout << "Enter a line of string: "; cin.getline(line, 150); for(int i = 0; line[i]!='\0'; ++i) { if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U') { ++vowels; } else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z')) { ++consonants; } else if(line[i]>='0' && line[i]<='9') { ++digits; } else if (line[i]==' ') { ++spaces; } } cout << "Vowels: " << vowels << endl; cout << "Consonants: " << consonants << endl; cout << "Digits: " << digits << endl; cout << "White spaces: " << spaces << endl; return 0; } ``` **輸出** ```cpp Enter a line of string: This is 1 hell of a book. Vowels: 7 Consonants: 10 Digits: 1 White spaces: 6 ``` * * * ## 示例 2:字符串對象 該程序從用戶那里獲取一個字符串對象,并計算元音,輔音,數字和空格的數量。 ```cpp #include <iostream> using namespace std; int main() { string line; int vowels, consonants, digits, spaces; vowels = consonants = digits = spaces = 0; cout << "Enter a line of string: "; getline(cin, line); for(int i = 0; i < line.length(); ++i) { if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U') { ++vowels; } else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z')) { ++consonants; } else if(line[i]>='0' && line[i]<='9') { ++digits; } else if (line[i]==' ') { ++spaces; } } cout << "Vowels: " << vowels << endl; cout << "Consonants: " << consonants << endl; cout << "Digits: " << digits << endl; cout << "White spaces: " << spaces << endl; return 0; } ``` **輸出** ```cpp Enter a line of string: I have 2 C++ programming books. Vowels: 8 Consonants: 14 Digits: 1 White spaces: 5 ```
                  <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>

                              哎呀哎呀视频在线观看