ex3_17.cpp

来自「Visual C++ 2005的源代码」· C++ 代码 · 共 37 行

CPP
37
字号
// Ex3_17.cpp : main project file.
// Analyzing a string using a for each loop

#include "stdafx.h"

using namespace System;


int main(array<System::String ^> ^args)
{
  int vowels = 0;
  int consonants = 0;
  String^ proverb = L"A nod is as good as a wink to a blind horse.";
  for each(wchar_t ch in proverb)
  {
    if(Char::IsLetter(ch))
    {
      ch = Char::ToLower(ch);      // Convert to lowercase
      switch(ch)
      {
      case 'a': case 'e': case 'i':
      case 'o': case 'u':
        ++vowels;
        break;
      default:
        ++consonants;
        break;
      }
    }
  }
  Console::WriteLine(proverb);
  Console::WriteLine(L"The proverb contains {0} vowels and {1} consonants.",
                                                              vowels, consonants);

    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?