diff mbox

std::getline

Message ID CAH6eHdQL3UoXwWdYL=9o5AS1APCB307U5x6RXyVBz7gzDxxZeA@mail.gmail.com
State New
Headers show

Commit Message

Jonathan Wakely May 15, 2013, 8:23 a.m. UTC
On 15 May 2013 08:50, Jonathan Wakely wrote:
> 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.

        * include/bits/basic_string.h (getline): Fix doxygen comments.

Committed to trunk so far.
commit 99b27b19b6a2f748c96fb1096f0d37925355213d
Author: Jonathan Wakely <jwakely.gcc@gmail.com>
Date:   Wed May 15 08:51:24 2013 +0100

    	* include/bits/basic_string.h (getline): Fix doxygen comments.

Comments

Jonathan Wakely May 15, 2013, 10:34 p.m. UTC | #1
On 15 May 2013 09:23, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 15 May 2013 08:50, Jonathan Wakely wrote:
>> Yes, it's wrong. I think the comment was copied from operator>> and
>> not corrected.  I'll fix it, thanks for reporting it.
>
>         * include/bits/basic_string.h (getline): Fix doxygen comments.
>
> Committed to trunk so far.

And the 4.7 and 4.8 branches.
diff mbox

Patch

diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index aa188f5..23bd9b9 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -2767,10 +2767,9 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *
    *  Stores characters from @a __is into @a __str until @a __delim 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 @a __delim was encountered,
-   *  it is extracted but not stored into @a __str.
+   *  is reached.  Any previous contents of @a __str are erased.  If
+   *  @a __delim is encountered, it is extracted but not stored into
+   *  @a __str.
    */
   template<typename _CharT, typename _Traits, typename _Alloc>
     basic_istream<_CharT, _Traits>&
@@ -2785,10 +2784,9 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *
    *  Stores characters from is into @a __str until &apos;\n&apos; 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.
+   *  is reached.  Any previous contents of @a __str are erased.  If
+   *  end of line is encountered, it is extracted but not stored into
+   *  @a __str.
    */
   template<typename _CharT, typename _Traits, typename _Alloc>
     inline basic_istream<_CharT, _Traits>&