使用以下代码时
#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++1z
和c++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如何向程序提交输入的问题。