String Constants (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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.

Code

#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";
	puts(str);

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

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

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

	return 0;
}

Uses

See Also