mercredi 9 octobre 2019

Problem with forming string array using loop

I want to create a string array using loop inputs and then give ASCII based output for each character of the string.

Here is my code

   cin>>n;
   string arr[n];
   for(int i=0;i<n;++i){
        getline(cin,arr[i]);
   }
   for(int i=0;i<n;++i){
    for(int j=0;j<arr[i].length();++j){
        cout<<to_string(arr[i].at(j))<<" ";
    }
    cout<<endl;
   }

the program takes n : number of string inputs.

However, during runtime , the programs terminates after taking only n-1 inputs and showing the desired result for the same.

What is the problem here?

Aucun commentaire:

Enregistrer un commentaire