以下是摘自CSDN上的一段文字
FIX: getline Template Function Reads Extra Character
修正: getline 模板函数读取额外字符
RESOLUTION
解决方案
Modify the getline member function, which can be found in the following system header file "string", as follows:
在系统头文件 string 中,修改 getline 成员函数的内容为以下形式(用记事本查找以下代码段定位):
else if (_Tr::eq((_E)_C, _D))
{_Chg = true;
// _I.rdbuf()->snextc(); // 删除这一行,加上以下一行
_I.rdbuf()->sbumpc();
break; }
STATUS
状态
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
微软已经证实这是列在本文开始处微软产品中发现的 Bug (这个中文怎么说来着?).
This problem was corrected in Microsoft Visual C++ .NET.
该问题已在 Microsoft Visual C++.NET 中修正.
MORE INFORMATION
更多信息
The following sample program demonstrates the bug:
以下程序演示该 Bug:
//test.cpp
#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