现在的位置: 首页 > 综合 > 正文

“getline” bug fix for Microsoft Visual C++ 6.0 关于VC6的getline输入需要两个回车才结束的BUG修改方法

2018年02月19日 ⁄ 综合 ⁄ 共 1704字 ⁄ 字号 评论关闭

今天看做C++ primer的习题遇到getline输入string的变量时候需要两个回车才能结束输入,网上找了好久,原来是VC6的BUG,找到了解决的办法如下:

简单总结就是随便建立个C++的CPP文件 写个#include<string>,右击string在弹出框中选择打开文档<string>,然后点编辑工具栏-->点查找 ,在查找栏输入else if (_Tr::eq((_E)_C, _D)),点查找下一个,将下图的左边代码部分改成右边部分,保存后退出即可:

original modified
else if (_Tr::eq((_E)_C, _D))
           {_Chg = true;
             _I.rdbuf()->snextc();
            break; }
else if (_Tr::eq((_E)_C, _D))
           {_Chg = true;
            //  _I.rdbuf()->snextc(); 
            // (this comments out the defective instruction)
           _I.rdbuf()->sbumpc(); // corrected code
            break; }

 

        "getline" bug fix for Microsoft Visual C++ 6.0

If you are compiling using Microsoft Visual C++, Version 6.0, and you are using getline to read into a string object, you may notice that the user will need to press "enter" twice in order to continue on. This is a compiler bug.

In order to correct the "getline" bug in Microsoft Visual C++, Version 6.0 , carefully perform the following steps:

  1. Right click on the word string in the #include <string> in your header
  2. Choose open document string from the resulting pull down menu
  3. Click on Edit, then Find
  4. Enter the following line in the Search box:

                                                           else if (_Tr::eq((_E)_C, _D))

 

     5.Make the following changes in code as shown:

      

original modified
else if (_Tr::eq((_E)_C, _D))
           {_Chg = true;
             _I.rdbuf()->snextc();
            break; }
else if (_Tr::eq((_E)_C, _D))
           {_Chg = true;
            //  _I.rdbuf()->snextc(); 
            // (this comments out the defective instruction)
           _I.rdbuf()->sbumpc(); // corrected code
            break; }
  1. Save and close the string header file.

You should only have to do this once on your home PC.  Unfortunately, if you want to do this in a student account, you may have to do this each time if you move to different machines, or if the machines have been re-imaged.

抱歉!评论已关闭.