Hello, I am trying to create a program that encodes the user's input then proceeds to decode it. It's been good until I reached the decoding stage. Instead of decoding the string it prints: Syntax error: "|" unexpected
2. Add some debug output, like the line 9 I added.
Then you see this
$ g++ foo.cpp
Enter text to be encoded into base64
DEBUG:>>echo hello | base64<<
| base64 --decode<<
sh: 2: Syntax error: "|" unexpected
Notice how the string printed between the >><< of the DEBUG contains a newline.
Also notice that line 2 of that output (see the error message) begins with the pipe character that the sh error message is complaining about.
In short, you're passing a string with a newline in it, and it's mangling your command string.