loop problem

why when i enter for example an input n=3,and then i enter only two strings not three strings ??!!
it should be
at i=0
at i=1
at i=2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
     int n,w,c;

     cin>>n;

     string s[n];

     for(int i=0;i<n;i++)
     {
         getline(cin,s[i]);
     }

     return 0;
}
You are not using a vector. You need to use:
1
2
 
std::vector<std::string> nameofyourvector;


(or in your case since you're using namespace std;)
 
vector<string> nameofyourvector


To declare a vector.
Last edited on
Mixing cin and getline can cause unforeseen issues i.e. what you are seeing. Look at http://www.cplusplus.com/forum/beginner/14595/ searching for cin.ignore(). Also look at http://www.daniweb.com/tutorials/tutorial71858.html#
Topic archived. No new replies allowed.