mardi 4 septembre 2018

how to loop over a getline() in C++?

I'm trying to loop over a getline() function but the programme just keeps skipping the cin statement for the loop variable and gets directly inside the loop which end up by crashing the programme!

a small snippet to clarify what I'm saying

int main() {
    int qur; cin>>qur; 

    for(int t = 0; t < qur; t++) {
        string cmd;
        getline(cin, cmd);  //it directly begins from here

I have no idea why is this happening, why would the compiler skip the cin statement and how to fix up this problem?

Aucun commentaire:

Enregistrer un commentaire