直接添加一行代码:
cin >> noskipws;
noskipws
实例:
#include<iostream>
using namespace std;
int main()
{
cin >> noskipws;//设置cin读取空白符;
char c;
size_t acount =0, ecount =0, icount =0, ocount =0, ucount = 0,scount = 0;
while (cin >> c)
{
if (c == 'a')++acount;
if (c == 'e')++ecount;
if (c == 'i')++icount;
if (c == 'o')++ocount;
if (c == 'u')++ucount;
if (c == ' ')++scount;
}
cout << "a: " << acount << endl;
cout << "e: " << ecount << endl;
cout << "i: " << icount << endl;
cout << "o: " << ocount << endl;
cout << "u: " << ucount << endl;
cout << "space: " << scount << endl;
return 0;
}
***运行结果:***
版权声明:本文为h593245631原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。