0

I need to cin an n and then n sentences, but it skips over the first position (i=0). So i took the program apart and made it simpler but it doesn't work, why it skips 0? I'm loosing my mind.

#include <iostream>
#include <cstring>
using namespace std;
int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++) {
        cout<<i<<' ';
        char p[255];
        cin.getline(p, 255);
    }
    return 0;
}
Loukas
  • 19
  • 3
  • 1
    OT: If you are permitted prefer to use `std::string` over a char array in c++. Also avoid using 1 letter variable names. Your variables should have names that tell you the purpose of the variable. Think of writing several thousand lines of code then waiting 6 months to have to debug it because a paying customer found some problem with his / her dataset. You will thank yourself for using descriptive variable names. – drescherjm Dec 26 '21 at 18:43

0 Answers0