程序输入(cin或getline)在运行时被正确读取,而在调试时却未被读取 [英] Program input (cin or getline) is read in correct when running but not when debugging

查看:177
本文介绍了程序输入(cin或getline)在运行时被正确读取,而在调试时却未被读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难用cin和/或getline的输入来调试C ++.当我运行而不是调试时,它可以完美运行.我在Windows 8.1和MinGW编译器/调试器(64位)中使用Eclipse Neon CDT.运行一个示例程序来隔离使用getline作为输入并提取第一个字符进行比较的问题:

I'm having trouble trying to debug C++ with input from cin and/or getline. It works perfectly when I run instead of debug. I'm using Eclipse neon CDT in Windows 8.1 with MinGW compiler/debugger (64bit). Running a sample program to isolate the issue that uses getline for input and extracts the first character for comparison:

while (true) {
  cout << "Enter x to exit: ";
  getline(cin, input);
  myChar = input[0];
  if (myChar=='x') {
    break;
  }

  cout << "You entered: " <<myChar<<endl;
}
cout <<"Exiting..."<<endl;

当我运行它时-它运行完美.但是,当我尝试调试时,它要么a)不等待输入并构成它自己,要么b)忽略我的输入并构成它自己.在不同的项目中进行实验时,我都看到了这两种情况.

When I run it - it works perfectly. However when I try to debug, it either a) doesn't wait for input and makes up it's own, or b) ignores my input and makes up it's own. I've seen both of these happen when experimenting in different projects.

我想也许我需要确保它正在将字符读为UTF-8.但是我发现的设置似乎是针对文本编辑器或文本文件的(Window-> Preferences-> General-> Workspace)...而不是控制台.

I thought maybe I needed to make sure it was reading chars as UTF-8. But the settings I found seem to be for the text editor or text files (Window->Preferences->General->Workspace)...not the console.

我了解到有时控制台输入存在问题,并尝试使用本机Windows控制台而不是IDE集成的控制台,如下所述:

I read that there are sometimes issues with console input and tried using native Windows console instead of the IDE integrated one as described here: http://nicolas.riousset.com/eclipse-how-to-debug-a-c-console-application-using-a-native-dos-console-instead-of-the-ide-integrated-one/

不幸的是,当我尝试启动调试器时,我得到一个错误:

Unfortunately then I just get an error when trying to launch the debugger:

最终启动序列中的错误无法执行MI命令:记录来自调试器后端的错误消息:进程记录:当前体系结构不支持记录功能.流程记录:当前架构不支持记录功能.

Error in final launch sequence Failed to execute MI command: record Error message from debugger back end: Process record: the current architecture doesn't support record function. Process record: the current architecture doesn't support record function.

推荐答案

不幸的是,当我尝试启动调试器时,我得到一个错误:

Unfortunately then I just get an error when trying to launch the debugger:

最终启动序列中的错误无法执行MI命令:记录来自调试器后端的错误消息:进程记录:当前体系结构不支持记录功能.流程记录:当前架构不支持记录功能.

Error in final launch sequence Failed to execute MI command: record Error message from debugger back end: Process record: the current architecture doesn't support record function. Process record: the current architecture doesn't support record function.

听起来您遇到了Eclipse Neon中的错误.

It sounds like you're running into a bug in Eclipse Neon.

该错误已在Neon.1更新中修复.如果您下载Eclipse的最新版本(在撰写本文时为Neon.3),它将包括修复程序.

The bug was fixed in the Neon.1 update. If you download the latest version of Eclipse (Neon.3 at the time of writing this) it will include the fix.

这篇关于程序输入(cin或getline)在运行时被正确读取,而在调试时却未被读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆