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

This article has been archived. It is offered "as is" and will no longer be updated.
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   WorldExpected Results:Hello<Enter Key>World<Enter Key>Hello   World				
STL
Properties

Article ID: 240015 - Last Review: 12/05/2015 15:36:05 - Revision: 4.0

  • kbnosurvey kbarchive kbtshoot kbprb kbbug kbfix kblangcpp kbnoupdate kbstl kbtemplate KB240015
Feedback
ERROR: at System.Diagnostics.Process.Kill() at Microsoft.Support.SEOInfrastructureService.PhantomJS.PhantomJSRunner.WaitForExit(Process process, Int32 waitTime, StringBuilder dataBuilder, Boolean isTotalProcessTimeout)ERROR: Error after PhantomJS process exit