samedi 9 juin 2018

string size limit input cin.get() and getline()

In this project the user can type in a text(maximum 140 characters). so for this limitation I once used getline():

  string text;
  getline(cin, text);
  text = text.substr(1, 140);

but in this case the result of cout << text << endl; is an empty string.

so I used cin.get() like:

cin.get(text, 140);

this time I get this error: no matching function for call to ‘std::basic_istream::get(std::__cxx11::string&, int)’

note that I have included <iostream>

so the question is how can I fix this why is this happening?

Aucun commentaire:

Enregistrer un commentaire