How do I get a number of sentences using a loop (while)?

I want to get some strings(sentences) from the input and save them on a map. But an error occurs.

int main() {
  string str_inputs;
  int num_inputs;
  int count = 0;

  cout << "Enter number of products:" << endl;
  cin >> num_inputs;
  cout << num_inputs << endl;

  cout << "Enter your products:" << endl;

  while (count < num_inputs) {
    string str_temp;
    cin.getline(str_temp, 100000);
    inputs.insert(pair<int, string>(count, str_temp));

“count”: This is the number of sentences we want to receive as input.

Error: no matching function for call to ‘std::basic_istream::getline(std::string&, int)’ }


cin.getline function takes a pointer to cstring as parameter, not an std::string : use a char buffer[] instead of a string; As mentionned in the comments, you can also use this function : std::getline(cin, str_temp)

Leave a Reply

Your email address will not be published. Required fields are marked *