Why is the program snippet giving error?

Why is the program snippet giving error?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main()
{
    string help;
    int len,n;string print_str="";
    cout<<"Enter the no. of inputs:- ";
    cin>>n;
    string str[n],st,new_str="";
    for(int i=0;i<n;i++)
    {
        gets(str[i]);
    }
    for(int j=n-1;j>=0;j--)
    {
        st=str[j];
        len=st.length();
        for(int k=len-1;k>=0;k++)
        {
            if(st[k]!=' ')
            new_str=st[k]+new_str;
            else
            {
                print_str=print_str+new_str;
                new_str="";
            }
            cout<<print_str<<endl;
            print_str="";
        }
    }
}
    
What error is program snippet giving?
Why is the program snippet giving error?

your compiler should tell you.
but the 'main' issue is this kinda thing:

1
2
3
4
int n;
	std::cout << "Enter the no. of inputs:- ";
	std::cin >> n;
	std::string str[n];


c-style array needs a constant expression. do you have to use c-style arrays?
Last edited on
The Error is in line no. 14
What error?
gets(...) does not take a string. Use getline(...) instead:

http://www.cplusplus.com/reference/string/string/getline/?kw=getline
Topic archived. No new replies allowed.