This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::getline
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: ntysdd <ntysdd at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 15 May 2013 08:50:25 +0100
- Subject: Re: std::getline
- References: <CADk2T0OBoUmrwwg7awN9a5wXi+MzypoHfUD1Y-bSBNFw6qYpuQ at mail dot gmail dot com>
On 15 May 2013 06:57, ntysdd wrote:
> Hi,
>
> 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;
> cin.width(3);
> getline(cin, s);
> cout << s << endl;
> return 0;
> }
>
> Maybe the comment is wrong?
Yes, it's wrong. I think the comment was copied from operator>> and
not corrected. I'll fix it, thanks for reporting it.