What is it called when you can fill a string with <<< and end-delimiter?

I know that in C ++ and in PHP you can fill a line or file with hard-coded text. If I remember correctly how it should 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 the title likes. But unnecessarily:

 foobar << "Menu for program X" << endl << "1.Add two numbers" << endl << "2.Substract two numbers" 
+4
source share
4 answers

He called the HEREDOC syntax in PHP:

 <?php $str = <<<EOD Example of string spanning multiple lines using heredoc syntax. EOD; ?> 
+4
source

C ++ has no equivalent to the PHP 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 is 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 the PHP 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 processed by the compiler as one long string, stitching them together. It has no other effect on the string literal, therefore, "\ n" is required.

+18
source

Multiline string literal?

+1
source

On Windows, you store long text as a resource or file.

You can save it to Unixish using the internationalization libraries (I18). This is a good hack to write a line in your program, for example printf( _("_xmenu_ %d, %d, %d"), 1, 2, 3) , and then you can translate _xmenu_ into English, as well into any other languages ​​you want to support. Since translations are stored in another file, you do not need to constantly look at them, and they are easy to change without recompiling.

+1
source

All Articles