String Constants (C++)

From RAD Studio Code Examples
Jump to: navigation, search


This example is a simple C++ console application that shows how string constants are handled in C++Builder.

In the example, a string is consecutively initialized with different string constants and afterwards outputs the string to the standard output.


#pragma hdrstop
#pragma argsused

#include <tchar.h>
#include <stdio.h>
#include <System.SysUtils.hpp>

int _tmain(int argc, _TCHAR* argv[]) {
	char* str;

	// initialize long string constants using separated strings
	// that are concatenated during the parsing phase
	str = "This is one way to " "initialize long string constants";

	// initialize long string constants using backslash(\)
	str = "This is another way \
to initialize string constants \
without writing the string constant \
on one single line";

	// escape sequences
	// \t \n \" \b
	str = "This string constant \t is formatted \nusing \"ess\bcape sequences\"";

	// \r \\
	str = "This part of the string will \
not be displayed because\r The \\r escape sequence \
resets the position of the output cursor";

	return 0;


See Also