В настоящее время у меня есть программа, которая читает со стандартного ввода, изредка программа должна просто продолжать работать, если вход не выполняется, обычно это тест script нет 'enter', так сказать.
program -v1 -v2 -v3 <input >output
v1 - v3 - аргументы командной строки, соответственно
В основном программа выплевывает аргументы командной строки и их соответствующее значение программе, если не задан "enter", а затем должен выйти.
Однако на данный момент, если вы даете ему пустой тестовый файл или просто запускаете без нажатия enter после запуска его блоков на std:: getline, я использую для ввода команд.
while(std::getline(std::cin,foo)
{do stuff}
где foo - строка.
Как мне заставить его просто запустить и do stuff
по крайней мере один раз, а затем выйти в случае отсутствия ввода? В случае ввода do stuff
происходит один раз для каждой строки стандартного ввода.
Работает ли переключатель в цикле do-while с предварительным циклом проверки того, получил ли он какой-либо вход?
Что-то вроде
if cin empty
set flag
do
{do stuff
check flag}
while(getline)
или не блокирует io невозможно в С++?
Этот вопрос, кажется, повторяется снова и снова, но я не мог найти окончательного ответа или даже ответа, который был несовместимым с платформой (эта программа носит академический характер, закодирована на окнах и протестирована в Unix).