c++中跳过空格简单统计输入单词的个数
#include<iostream>
#include<windows.h>
#include<string>
using namespace std;
int main(void) {
char a[256];
int i = 0;
int count = 0;
cout << "请输入单词" << endl;
gets_s(a, sizeof(a));
while (a[i] == ' ') i++;
while (a[i]) {
while (a[i] && a[i] != ' ') i++;
while (a[i] == ' ') i++;
count++;
}
cout << "单词数为:"<< count << endl;
string naem;
getline(cin, naem);
system("pause");
return 0;
}