【问题标题】:Is this a g++ or CLion bug ( using Ctrl+D in CLion)?这是 g++ 还是 CLion 错误(在 CLion 中使用 Ctrl+D)?
【发布时间】:2020-03-31 12:59:30
【问题描述】:

关于使用以下代码

#include <iostream>
#include <vector>
#include <string>

int main()
{

    std::vector<std::string> vec;
    std::string temp{};
    while(std::cin >> temp) vec.push_back(temp);

    std::cout << "\n[ " << vec[0];
    for(int i {1}; i < vec.size(); i++) std::cout << ", " << vec[i];
    std::cout << "]";

}

使用以下输入

kghukg kjhukg 6887 ^D

我明白了

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

我在 ubuntu 和

上使用 CLion
asmmo@asmmo:~$ g++ --version
g++ (Ubuntu 9.3.0-8ubuntu1) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

std=-s++1zc++2a 出现该错误

考虑到评论,我将代码更新为

#include <iostream>
#include <vector>
#include <string>
#include <thread>
using namespace std::chrono_literals;
int main()
{

    std::vector<std::string> vec;
    std::string temp{};
    while(std::cin >> temp) vec.push_back(temp);
    std::cout<<vec.size();
    std::this_thread::sleep_for(10s);
    std::cout << "\n[ " << vec[0];
    for(int i {1}; i < vec.size(); i++) std::cout << ", " << vec[i];
    std::cout << "]";

}

然后使用

kjjkj jkh 555 ^D

但它等待thwn除了错误没有显示任何东西

【问题讨论】:

  • 也许,在std::cout &lt;&lt; "\n[ " &lt;&lt; vec[0]; 输出之前,您可以检查vec 中是否有任何内容。虽然,我不清楚为什么vec 在输入kghukg kjhukg 6887 ^D 后仍然应该为空(但谁知道......)
  • @ThomasSablik 这就是我在更新中所做的。尺寸无法显示
  • @asmmo 使用 std::cout &lt;&lt; vec.size() &lt;&lt; std::endl;
  • @ThomasSablik 可能是 clion 中的一个错误。我使用终端,一切正常。

标签: c++ g++ clion


【解决方案1】:

我的心理猜测是,这是 CLion 如何向程序提交输入的问题。

https://youtrack.jetbrains.com/issue/CPP-5704

我可以禁用 ⌘+D 和 Ctrl-D 的键帽,并依靠“发送 EOF”操作或禁用 Clion 键帽的 ⌘-D 和 Ctrl-D 按键,结果是相同的:程序没有收到 EOF 但收到某种终止信号。

显然有些人找到了规避此问题的方法:

https://xbuba.com/questions/45803954

在注册表中禁用 run.processes.with.pty(通过查找操作打开)通常会有所帮助。

我从不理解 Jetbrains 工具的炒作...

【讨论】:

    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 1970-01-01
    相关资源
    最近更新 更多