// ConsoleApplication1.cpp: 定義控制台應用程式的入口點。//#include "stdafx.h"#include <iostream>#include <string>using namespace std; int countnubstr(string str){ i ...
// 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();
}