There's nothing magical about piping to your program it just turns your cin reading from the stream instead of the user's input from the console: Linux terminal pipe to my C++ program
A simple glance at this question's edit history will show that this question has greatly improved from it's original version thanks to Konrad Rudolph (the other answerer on this question.) In a move of further dastardliness I'm going to scrape 2 of his solutions for slurping a stream into string:
istreambuf_iterator method:
const string mkfifo{ istreambuf_iterator<char>(cin), istreambuf_iterator<char>() };
stringbuf copy method:
istringstream temp;
temp << cin.rdbuf();
const auto mkfifo = temp.str();
You can read about the pros and cons of each on their respective posts. To use this code, say that your compiled program is named main you would pipe to it like this:
mkfifo named_pipe
echo "lorem ipsum" > named_pipe
./main named_pipe