'How to exit from .out file to add string to stdin?
I'd like to add every line to stdin, but I can't because a.out doesn't exit from loop.
C++ code:
#include <iostream>
int main() {
std::string in;
while(1){
std::cin >> in;
if(in == "exit")
break;
std::cout <<in << "\n";
}
return 0;
}
And a bash code:
#!/bin/bash
while read -r line
do
echo "$line" | ./a.out >> output.txt
done < "input.txt
Thanks!
Solution 1:[1]
your C++ part works perfectly. But as soon as it exits, you again do while read -r line. Try to enter EOF just after "exit" line.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dmitry |
