The problem is that in the reader, you are calling getline(), which clears the pipe that echo was waiting on, and then there is a basic "race condition" between the proceses: if the bash script manages to add another line in its loop before the reader loop calls getline() again, then you are in luck. If not, there is no line to get and so getline() fails and the while loop exits.
You could solve this problem a few different ways. You could try using
& with echo in the bash loop, but that is still not a guarantee it will keep up, and if it does, it may create an undesirable number of forks.
The simplest would be to just feed the whole file at once into the pipe: