c++ - 这是g++还是CLion错误(在CLion中使用Ctrl + D)?

标签 c++ g++ clion

关于使用以下代码

#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

但是它等待着除了错误以外什么也没显示

最佳答案

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

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

I can disable keycaps for ⌘+D and Ctrl-D, and rely on the "Send EOF" action or the ⌘-D and Ctrl-D keypresses with Clion keycaps disabled, the result is the same: the program does not receive a EOF but receives some sort of kill signal.



显然,有些人找到了避免这种情况的方法:

https://xbuba.com/questions/45803954

Disabling the run.processes.with.pty in Registry (open via Find Action) usually helps.



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

关于c++ - 这是g++还是CLion错误(在CLion中使用Ctrl + D)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60951147/

相关文章:

C++浮点问题

c++ - 在自定义类中实例化自定义类时出现 "expected type-specifier"错误

c++ - 将 nullptr 传递给 C 函数是否安全?

c++ - Linux 上的 CMake FindJNI 问题

c++ - 如何将CLion C++项目导入Visual Studio?

c++ - 将输入值存储到数组中,同时读取它们,C++

c++ - 如何使整个 GridView 行垂直展开

gcc - 在 pwd 中编译文件时,让 gcc/g++ 使用绝对路径进行警告

c++进程在两个子进程之间进行管道连接时挂起

c++ - 计算包含对象的this指针