Hello,
My program is not taking ‘n’ inputs, instead, it is taking ‘n-1’ inputs.
I tried to take array of strings.
Below is my code:
‘#include’<‘algorithm’>
‘#include’ <‘string’>
‘#include’ <‘algorithm’>
using namespace std;
int main(){
int n;
cin>>n;
string s[n];
for(int i=0;i<n;i++){
getline(cin,s[i]);
}
sort(s,s+n);
for(int i=0;i<n;i++){
cout<<s[i]<<endl;
}
return 0;
}
Input :
3
apple juice
mango juice
// It is not taking 3rd input
Output:
Apple juice
mango juice
Maybe because I have not put cin.get() here. But, what is the use of cin.get() in this context?