1

I have written the following code:

#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main() {

    int requirements, proposals;
    string inutil_string;

    while(scanf("%d %d", &requirements, &proposals), (requirements || proposals)) {
        cout << proposals << endl;
        for(int i = 0; i < requirements; i++) {
            getline(cin, inutil_string);
            cout << inutil_string << endl;
        }

    }
}

When I run the program, it does not read the string from the console through the getline() method and the line that contains cout does not show anything in the "inutil_string". Why do I obtain this behavior?. Note that the while loop must stop when "0 0" is typed.

Lemark
  • 137
  • 3
  • 10
  • scanf() is a C library function. std::getline() is a C++ library function. Neither one really knows much about the other, and both of them should not be used in the same code. – Sam Varshavchik Jul 11 '16 at 01:13

0 Answers0