这个是出问题的程序:

#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这个语句输出。

最后在microsoft得解:

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 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();

_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

我给大家解释下意思吧:

症状:

c++的标准库模板函数getline在读到限定符后还要读取额外字符...

解决方法:

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

{

_Chg = true;

// _I.rdbuf()->snextc();

_I.rdbuf()->sbumpc();

break;

}

修改系统头文件时大家要小心点...

现状:

微软已经确认这是他们产品中的'臭虫'(bug),这个bug已经在Microsoft Visual C++ .NET得到修正.

案例:

如上...

snextc:Advances the get pointer, then returns the next character.

stossc:Moves the get pointer forward one position, but does not return a character.

getline 两次回车 解决办法相关推荐

  1. 无线网卡丢失的两个奇葩解决办法

    无线网卡丢失的两个奇葩解决办法 昨天开始自己的笔记本 (ThinkPad E430) 就显示没有无线网卡了.360wifi 无法使用,无法发现无线网络.试图重装了驱动,重启电脑数次.依然无果,最后在网 ...

  2. 斑马打印机 GK888t打印标签一次出两张的解决办法

    因工作需要,单位用斑马GK888t条码打印机打印标签时,总是一次打印两张,一张有内容一张空白. 从网上找到了解决办法,亲测可用,方法是长按打印机上面的绿色开机键,几秒钟后,指示灯会快速的闪动,等待五次 ...

  3. xstart里输入一个字母,自动显示两个字母解决办法

    一 问题描述 我在xstart里输入一个字母如x,则自动会显示两个字母xx. 二 解决办法 打开xstart的会话页面,点击'高级': 点击'配置': 点击'高级',取消勾选'XKEYBOARD': ...

  4. WORD出现两个mathtype解决办法,超简单

    WORD出现两个mathtype 其中一个是灰的,不能用,另一个能用.保留其中能用的一个 解决办法: 点击:文件->选项->加载项 选择其中的一个mathtype开头的(我的是前面一个是灰 ...

  5. php 两次post,ajax跨域往php程序post数据时,php程序总是执行两次的解决办法

    ajax跨域往php程序post数据时,php程序总是执行两次的解决方法 php程序是部署在IIS7上面,ajax提交数据时,遇到了两个问题,一个就是跨域,一个php程序总会被执行两次. 第一个问题的 ...

  6. win10系统不识别耳机 + 扬声器产生‘啪’的电流声音两种情况——解决办法

    1. 电脑扬声器出现问题,不识别耳机 我的是Dell电脑,inspiration系列,重装了系统之后出现插入耳机不被识别,还是放外音的情况.驱动问题. 解决方法: 控制面板-->设备管理器(或右 ...

  7. Ubuntu 开机黑屏两大原因解决办法

    1. nvidia 驱动问题 在卡机的时候在选择Ubuntu开机的时候按 e 进入启动文件的 "edit" 模式; 修改 'ro' 为 'rw' 代表 read& writ ...

  8. 点击TableView任一行跳转详情页面会跳转两次的解决办法

    在做TableView跳转的时候,发现实际上生成了两个detail view.我 navigate back 的时候,也是先看到一次detail view,然后才回到tableView的. 这是因为: ...

  9. QT中button中没有accept()和reject()这两个槽解决办法

    这两个是QDialog里才有的,用如下的步骤之后可以调用accept()和reject()这两个槽 点击QT设计师类 我选择的是没有按键的,按键一会可以自己添加 类名可以自己写,然后点击下一步即可 最 ...

最新文章

  1. CISCO设备部分型号IOS下载
  2. centos7安装postgresql数据库
  3. 安装部署及升级到Exchange Server 2010
  4. mysql插入时间区间_mybatis插入数据时返回主键以及MySQL根据时间区间查询问题总结...
  5. efcore 实体配置_创建并配置模型
  6. 【CodeForces - 155C】Hometask (字符串,思维,贪心,熟悉句式)(总结)
  7. 线程 协程 python_在Python 的线程中运行协程的方法
  8. oracle中的序列 cache,oracle row cache lock 之sequence
  9. Java线程池 面试考点
  10. 网摘Android调用WebService
  11. 基于stylus的border一像素线问题与ellipsis多行的兼容方案
  12. linux达梦数据库执行sql脚本
  13. 计算机校准颜色,显示器颜色校正,教您怎么校准显示器颜色
  14. jq追加html点击事件,jq增加点击事件 Jquery为DIV添加点击事件
  15. 使用阿里云云服务器遇到大流量攻击怎么防御
  16. teemo使用手册(内附脚本一键提取,邮箱、IP、domain、whatweb筛选可打开网址)
  17. Beamer Template
  18. 项目Beta冲刺(7/7)(追光的人)(2019.5.29)
  19. 智能车浅谈——抗干扰技术软件篇
  20. Android BLE4.+ 蓝牙开发国产手机兼容性解决方案

热门文章

  1. LCD 调试技巧 01
  2. 【模电学习笔记①】静态工作点的设置、截止失真和饱和失真
  3. uni-app图片上传(位置固定)
  4. Python笔记_81_结算页面_订单模型_优惠券
  5. Linux运维工程师主要做什么工作?
  6. 最详细的MySQL大表优化方案
  7. unity按钮的使用
  8. 暨南大学计算机科学研究生,计算机科学系硕士研究生在IEEE Virtual Reality (VR) 2020上发表两篇论文...
  9. 关于 Shell 脚本的经典十三问
  10. 手把手教程|构建无服务器通用文本识别功能