I know in C++ and in PHP you can fill a string or a file with hard-coded text. If I remember correctly this is how it is supposed to look:
var <<< DELIMITER
Menu for program X
1.Add two numbers
2.Substract two numbers
3.Multiply two numbers
Please pick an option from (0-3);
DELIMITER
This can be used for menus or text that remains the same no matter what like a header. But without having to do:
foobar << "Menu for program X" << endl << "1.Add two numbers" << endl << "2.Substract two numbers"
C++ doesn't have any equivalent to PHP's HEREDOC syntax.
You can, however, do this in C++:
cout << " Menu for program X\n"
" 1.Add two numbers\n"
" 2.Substract two numbers\n"
" 3.Multiply two numbers\n"
" Please pick an option from (0-3);" << endl;
Or this in C:
printf( " Menu for program X\n"
" 1.Add two numbers\n"
" 2.Substract two numbers\n"
" 3.Multiply two numbers\n"
" Please pick an option from (0-3);\n" );
fflush(stdout);
Which is directly equivalent to PHP's HEREDOC syntax:
echo <<<EOT
Menu for program X
1.Add two numbers
2.Substract two numbers
3.Multiply two numbers
Please pick an option from (0-3);
EOT;
The above syntax for C and C++ is treated by the compiler as one long string, by stitching them together. It has no other effect on the string literal, hence the need for '\n'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With