BUG: getline Template Function Reads Extra Character

ID: Q240015


The information in this article applies to:
  • The Standard C++ Library, included with:
    • Microsoft Visual C++, 32-bit Editions, version 6.0


SYMPTOMS

The Standard C++ Library template getline function reads an extra character after encountering the delimiter. Please refer to the sample program in the More Information section for details.


RESOLUTION

Modify the getline member function, which can be found in the following system header file string, as follows:


	else if (_Tr::eq((_E)_C, _D))
                {_Chg = true;
              //  _I.rdbuf()->snextc(); /* Remove this line and add the line below.*/ 
		  _I.rdbuf()->sbumpc();
                break; }
 
NOTE: Because the resolution involves modifying a system header file, extreme care should be taken to ensure that nothing else is changed in the header file. Microsoft is not responsible for any problems resulting from unwanted changes to the system header files.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

The following sample program demonstrates the bug:


//test.cpp
//Compiler options : /GX
#include <string>
#include <iostream>
int main () {
	std::string s,s2;
	std::getline(std::cin,s);
	std::getline(std::cin,s2);
	std::cout << s <<'\t'<< s2 << std::endl;
	return 0;
}

Actual Results:
Hello<Enter Key>
World<Enter Key>
<Enter Key>	
Hello   World

Expected Results:
Hello<Enter Key>
World<Enter Key>
Hello   World 

Additional query words: STL

Keywords : kbtemplate kbLangCPP kbSTL kbVC kbVC600 kbVC600bug
Version : winnt:6.0
Platform : winnt
Issue type : kbbug


Last Reviewed: September 16, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.