未读取空格
Whitespaces are not being read
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int vovles_count[5] = { 0,0,0,0,0 };
char vovwls[5] = { 'a','e','i','o','u' };
char vov;
int nonVov = 0 , punt = 0 , douseq = 0;
//std::cin >> std::noskipws; //tells not to skip white spaces
while (cin >> vov)
{
switch (vov)
{
case 'a':
++vovles_count[0];
break;
case 'e':
++vovles_count[1];
break;
case 'i':
++vovles_count[2];
break;
case 'o':
++vovles_count[3];
break;
case 'u':
++vovles_count[4];
break;
case ' ':
++punt;
break;
case 'n':
++punt;
break;
case 'f':
cin >> vov;
if (vov == 'l' || vov == 'f')
{
++douseq;
++nonVov; //previous f
++nonVov; //current f
}
else if (vov == 'i')
{
++vovles_count[2];
++douseq;
++nonVov; //previous f
}
else if (vov == ' ' || vov == 'n')
++punt;
break;
default:
++nonVov;
break;
}
}
for (int i = 0; i < 5; ++i)
{
cout << vovwls[i] << " occured for " << vovles_count[i] << "times" << 'n';
}
cout << 'n' << nonVov << " are the occurence of non vovels " << 'n' ;
cout << 'n' << punt << " are the occurence of whitespaces " << 'n';
cout << 'n' << douseq << " are the occurence of double sequence " << 'n';
system("pause");
return 0;
}
我认为我在代码中没有看到任何问题,但我不知道为什么没有读取空格?
使用 CIN 默认情况下会跳过空格。 您可以尝试其他方法:
cin.get((;
正是这个函数的代码重载将帮助您:
istream& get (char* s, streamsize n, char delim);
将 '' 放入 delim 以结束输入行,按回车键
相关文章:
- 如何在C++中读取空格分隔的输入 当我们不知道输入的数量时
- 如何将以逗号和空格分隔的整数读取到 2D 数组中?
- 如何在 C++ 中从文件中读取字符数组(带有一些空格)
- 如何逐行读取文件,每行中的内容都用空格分隔并将其写入新文件中
- 文件读取C++包括空格键
- 忽略从文件中读取前导空格
- 从文本文件中读取所有内容,直至空格
- 在C++中读取带空格的字符串
- 如何从文件中读取用空格分隔的数字
- C++ 逐行从文件(包含空格)读取数据
- 如何在 c++ 中将文件中的无空格插入器读取到数组中?
- 从文本文件中读取数据并删除所有换行符空格,并在 C++ 控制台中显示
- 从文件中读取多行.txt字符串删除空格并创建新文件进行输出
- 如何读取文件忽略第一个空格?
- 如何在C++中读取带有空格的字符串
- C++ : 如何在使用 getline() 和 ifstream 对象从文件中读取一行时跳过第一个空格?
- 如何在 c++ 中读取输入字符串,忽略空格
- 如何使用 istream_iterator 从 ifstream 中读取带有空格的字符串?
- 为什么在写入文件时删除空格无法读取文件
- 使用delimeter和多个空格读取txt