C++ 输入有空格一行的接收
生活随笔
收集整理的這篇文章主要介紹了
C++ 输入有空格一行的接收
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include<iostream>
#include<string>
using namespace std;
int main()
{char input_str[100]; //輸入有空格的一行。cin默認以空格結束cin.getline(input_str, 100);int num_num = 0;int num_letter = 0;int num_space = 0;int num_other = 0;int len = strlen(input_str);cout << "len:" << len<<endl;for (int i = 0; i<len; i++) {if (input_str[i] >= '0' && input_str[i] <= '9')num_num++;else if ((input_str[i] >= 'A' && input_str[i] <= 'Z') || input_str[i] >= 'a' && input_str[i] <= 'z')num_letter++;else if (input_str[i] == ' ')num_space++;elsenum_other++;}cout << "letter:" << num_letter << endl;cout << "number:" << num_num << endl;cout << "space:" << num_space << endl;cout << "other character:" << num_other << endl;return 0;
}
?
總結
以上是生活随笔為你收集整理的C++ 输入有空格一行的接收的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: opencv12-图像金字塔
- 下一篇: LNK2019 无法解析的外部符号 __