#include <iostream>
using namespace std;
int main()
{
char c;
cout << "Please input some charactors: \n";
cin >> c;
int letters = 0, space = 0, digit = 0, others = 0;
while (c != '\n')
{
if (c >= 'a'&&c <= 'z' || c >= 'A'&&c <= 'Z')
letters++;
else if (c == ' ')
space++;
else if (c >= '0'&&c <= '9')
digit++;
else
others++;
}
cout << "char=" << letters << "space=" << space++ << "digit=" << digit << "others" << others;
}
uj5u.com熱心網友回復:
你的意思是要重復輸入一直到輸入回車結束嗎?cin >> c; 沒有在回圈中。
uj5u.com熱心網友回復:
cin讀取不了回車和空格轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/72771.html
標籤:基礎類
