I am trying to get the length of the words which I have stored in a string array.First,I specify the number of words in an array using 'n'(input from user), then I take inputs from the user of the 'n' words they want to store. After that, I wish to print the length of a word.
Here is the code....
#include <iostream>
using namespace std;
int main(){
int n;
cout<<"enter no"<<endl;
cin>>n;
string A[n];
for(int i=0;i<n;i++){
cin>>A[i];
}
cout<<strlen(A[2])<<endl;
}
For example, if inputs are:
3
leonardo
tom
brad
(They are written in separate lines)
then output should be :
4
which is length of brad
.
But I get a strange error while execution of this code. Please suggest a way to do this , while taking inputs from the user in separate lines