C++ 统计输入的句子有多少英文字母

// ConsoleApplication1.cpp: 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int countnubstr(string str)
{
int returnnum = 0;
for (int i = 0; i<str.length(); i++)
{
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
{
returnnum++;
}
}
return returnnum;
}

void main()
{
string str;
cout << "Please input English Line" << endl;
//流输入一串英文句子。
getline(cin,str);
cout << endl<< "There is " << countnubstr(str) << "noumber words int this English Line" << endl;
getchar();
}

猜你喜欢

转载自www.cnblogs.com/anyeliuguang/p/10887596.html