This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]



I found this in the file `include\bits\basic_string.h':
* @brief Read a line from stream into a string.
* @param __is Input stream.
* @param __str Buffer to store into.
* @return Reference to the input stream.
* Stores characters from is into @a __str until '\n' is
* found, the end of the stream is encountered, or str.max_size()
* is reached. If __is.width() is non-zero, that is the limit on
* the number of characters stored into @a __str. Any previous
* contents of @a __str are erased. If end of line was
* encountered, it is extracted but not stored into @a __str.
template<typename _CharT, typename _Traits, typename _Alloc>
inline basic_istream<_CharT, _Traits>&
getline(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT, _Traits, _Alloc>& __str)
{ return getline(__is, __str, __is.widen('\n')); }

But in reality I found __is.width() seemed to be completely ignored.
For example:

#include <iostream>
#include <string>
using namespace std;
int main(void)
  string s;
  getline(cin, s);
  cout << s << endl;
  return 0;

Maybe the comment is wrong?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]