个人觉得的有用的文档,贴出来和大家分享
vc6 getline 两个回车bug解决
上一篇 /
下一篇 2008-05-15 16:36:27
/ 个人分类:c++
#include <iostream>
#include <string>
int main()
{ using namespace std;
string str;
std::cout<<"Please input your name:\n";
getline(cin,str);
std::cout<<"Hello,"<<str<<"!!\n"; }
比如说,我们输入"virus welcome back!",但是当我们输入后按回车,程序并不运行cout语句,而是光标还在编绎窗口上闪动,要再按一下[ENTER]才会运行cout这个语句输出,最后在microsof得解: The getline template function reads an extra character after encountering the delimiter该文件的一般路径:C:\Program Files\Microsoft Visual Studio\VC98\Include\string 注意是string文件,不是string.h,修改后问题解决 | Article ID | : | 240015 |
| Last Review | : | September 2, 2005 |
| Revision | : | 3.0 |
This article was previously published under Q240015
SYMPTOMS
The Standard C++ Library templategetlinefunction reads an extra character after encountering the delimiter.
Please refer to the sample program in the More Information section for
details.
RESOLUTION
Modify the
getlinemember 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; }
NoteBecause 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
我给大家解释下意思吧:症状:
c++的标准库模板函数getline在读到限定符后还要读取额外字符...
解决方法:
else if (_Tr::eq((_E)_C, _D))
{_Chg = true;
// _I.rdbuf()->snextc(); /* 把这一行注释掉,添加下一行.*/
_I.rdbuf()->sbumpc();
break; }
修改系统头文件时大家要小心点...
现状:
微软已经确认这是他们产品中的'臭虫'(bug),这个bug已经在Microsoft Visual C++ .NET得到修正.
相关阅读:
- windows驱动程序安装 (brace, 2008-1-22)
- 64位gcc 编译32 程序 (brace, 2008-3-14)
- 李开复回京解决公关危机 举报源头成迷 (linuxpk, 2008-3-21)
- Sun发布MySQL 5.1版 修复Bug大幅升级 (kennycx, 2008-4-16)
- nagios二 客户端程序的安装 (zzxia, 2008-4-17)
- 显示桌面小程序的软件-gdesklets, screenlets (liyropt, 2008-4-22)
- 独立客户端版的 Linux 飞信(08.4.29更新,解决8.0.4不能运行问题) (linuxpk, 2008-5-03)
- VIA 向社区开放 16,434 行驱动程序代码 (kennycx, 2008-5-12)
- 深藏25年的操作系统Bug被消灭 (linuxpk, 2008-5-12)
导入论坛
收藏
分享给好友
管理
举报
TAG:
Bug
程序
解决
getline
bug
回车