Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 10: Characteristics of a Window's Frame


You can also get the same result by calling the size() method whose syntax is:

size_type size() const;

Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
string StrName("Central African Republic");

int Len = StrName.length();
pDC->TextOut(20, 22, StrName.c_str(), Len);
}

9.1.4 String Formatting.................................................................................


Formatting a string consists of telling the compiler how to adjust, before using such as
displaying, the string. Imagine you declare a null-terminated string as follows:

char Represents[20];

To format a null-terminated string, you can call the sprintf() function. Its syntax is:

int sprintf(char* Buffer, const char* S, Arguments...);

This function takes at least two arguments but can take as manu as necessary. The first
argument, Buffer, is a null-terminated string variable:

char Represents[20];
sprintf(Represents,

To display a value as part of the Buffer variable, provide the second argument starting it
with a double-quote followed by a string if any, followed by the % sign, followed by one
of the following characters:

Character Type of Data Used for

c char A single character
d int Any signed decimal integer (int, short)
i int Any signed decimal integer (int, short)

o

Signed
Integers

An unsigned octal integer

u Unsigned

Any unsigned decimal integer (unsigned,
unsigned int)

x Unsigned

Any unsigned lowercase hexadecimal integer
(abcdef)

X Unsigned

Any unsigned uppercase hexadecimal integer
(ABCDEF)

e double

Scientific representation of a signed value used
to display the lowercase exponent

E double

Scientific representation of a signed value used
to display the uppercase exponent

f double

Representation of a floating point number with
a specific number of characters to the right of
Free download pdf