In a problem were i have to take n number of strings as input and count the ones containing a given substring(case insensitive).
Here's my code:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<string>
using namespace std;
int main()
{
    std::string str2 = "hello";
    std::string str3 = "HELLO";
    short int n,count=0,i;
    cin>>n;
    std::string str1[n];
    for(i=0;i<n;i++)
    {
        std::getline(std::cin,str1[i]);   //here getline is taking only n-1  inputs
        std::size_t found1=str1[i].find(str2);
        std::size_t found2=str1[i].find(str3);
        if(found1!=std::string::npos || found2!=std::string::npos)
            count++;
    }
    cout<<count;
    return 0;
}
Since i cant use cin as string includes spaces or cin.getline() as have to use string type in place of char[].
Problem with my code is std::getline() is only taking n-1 inputs.Cant figure out why?
 
     
     
    