相关疑难解决方法(0)

如何在c ++中使用cin?

假设我们有一个代码:

int main()
{
   char a[10];
   for(int i = 0; i < 10; i++)
   {
       cin>>a[i];
       if(a[i] == ' ')
          cout<<"It is a space!!!"<<endl;
   }
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

如何从标准输入中删除空格符号?如果你写空间,程序会忽略!:(是否有任何符号组合(例如'\ s'或类似的东西),这意味着我可以从我的代码的标准输入中使用"空间"?

c++ spaces cin

29
推荐指数
4
解决办法
12万
查看次数

如何计算特定字母在字符串中出现的次数?(C++)

我一直在努力完成一项家庭作业,该作业计算字符串中大写字母、小写字母和数字的实例数量。出现在一个字符串中。

我正在使用一个大小为 132 的常量一维数组来存储输入的字符串,我需要使用两个函数。一个需要计算字符串中字母出现的数量,另一个函数将执行类似于上面的输出。我在程序本身的字母计数方面最挣扎。

目前,这就是我目前的家庭作业的大部分内容。这是一项正在进行的工作(当然),因此代码中很可能出现错误。

void LetterCount(char c_input[], int l_count)
{
// code to count letters
}

void CountOut(//not sure what should go here yet until counting gets figured out)
{
// code that handles output
}

int main()
{
    const int SIZE = 132;
    char CharInput[SIZE];
    int LetterCount = 0;
    cout << "Enter a string of up to 132 characters in size: ";
    cin.getline(CharInput, SIZE); 
    cout << "You entered: " << CharInput << endl;

    Count(CharInput);
    CountOut(//not sure what goes …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

2
推荐指数
1
解决办法
1052
查看次数

标签 统计

c++ ×2

c++11 ×1

cin ×1

spaces ×1