При использовании следующего кода
#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)
Я использую CLion на Ubuntu и
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
но ожидал, что ничего не отображается, кроме ошибки