The getline template function reads an extra character after encountering the delimiter

Article translations Article translations
Article ID: 240015 - View products that this article applies to.
This article was previously published under Q240015
Expand all | Collapse all

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 that this is a bug in the Microsoft products that are listed in the "Applies to" section. This problem was corrected in Microsoft Visual C++ .NET.

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
				

Properties

Article ID: 240015 - Last Review: September 2, 2005 - Revision: 3.0
APPLIES TO
  • The Standard C++ Library, when used with:
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++ 6.0 Standard Edition
Keywords: 
kbtshoot kbbug kbfix kbnoupdate kblangcpp kbtemplate kbstl kbprb KB240015

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com