Format Specifiers in C++

When debugging native code in the Watch window or QuickWatch dialog box, you change the format in which a value is displayed using format specifiers.

(Most format specifiers are for native code only, but Visual C# has a limited set of format specifiers. See Format Specifiers in C#.)

You can also use format specifiers in the Immediate window, the Command window, and even in source windows. If you pause on an expression in those windows, the result will appear in a DataTip. DataTips will reflect the format specifier in the DataTip display.

Note

The Visual Studio native debugger transitioned to a new debugging engine. Included in this change was the addition of some new format specifiers and the removal of some old ones. The transition is not complete, and the older debugger is still used when you do interop (mixed native and managed) debugging with C++/CLI, and when you debug using C++ edit and continue. Sections in this topic show the format specifiers for each debug engine.

  • Visual Studio 2012 format specifiers describes the format specifiers in the new debugging engine.

  • Format specifiers for interop debugging and C++ edit and continue describes the format specifiers in the older debugging engine.

Contents

Example

Visual Studio 2012 format specifiers

  • Size specifiers for pointers as arrays in Visual Studio 2012

Format specifiers for interop debugging and C++ edit and continue

  • Format specifiers memory locations in interop debugging and C++ edit and continue

  • Size specifier for pointers as arrays in interop debugging and C++ edit and continue

Example

Suppose nVar is an integer variable, and the Watch window shows that it contains the value 0x0065. To see value expressed as a character instead of an integer, in the Name column, after the variable name, add the character format specifier, c:

Instead of the integer value 0x0065, the Value column now displays the character value, 101 'e'.

If you want to apply a format specifier to elements of an array or members of an object, you must apply it directly to each element or member. You cannot apply it to the array or object as a whole. For example, suppose you had an array nArray and wanted to see the first four elements in character format. You would enter these expressions in the Watch window:

nArray[0],c
nArray[1],c
nArray[2],c
nArray[3],c

Visual Studio 2012 format specifiers

The following tables show the format specifiers that you can use in Visual Studio 2012 when you are not debugging interop (native and managed) code with C++/CLI or using C++ edit and continue.

Specifiers in bold are not supported for interop debugging with C++/CLI or debugging with C++ edit and continue.

Specifier

Format

Expression

Value Displayed

d

decimal integer

0xF000F065, d

-268373915

o

unsigned octal integer

0xF065, o

0170145

x

h

Hexadecimal integer

61546, x

61541, h

0x0000f06a

X

H

Hexadecimal integer

61541, X

61546, H

0x0000F06A

c

Single character

0x0065, c

101 'e'

s

ASCII string

0x0012fde8, s

"Hello world"

sb

ASCII string

0x0012fde8, sb

Hello world

su

Unicode string

0x0012fde8, su

L"Hello world"

sub

Unicode string

0x0012fde8, sub

Hello world

s8

UTF-8 string

0x0012fde8, s8

"Hello world"

s8b

UTF-8 string

0x0012fde8, s8b

Hello world

bstr

BSTR string

0x0032fe8, bstr

Hi there

en

Used on expression evaluating to a C++ enum type. Displays only the name of the enum constant, omitting the numerical value.

enumValue,en

EnumValue

, na

&myGlobal, n

winmain, na

The address of the pointer is not displayed.

nd

pb,nd

Displays only the base class info of pb, ignoring derived classes

hr

HRESULT or Win32 error code. (The debugger now decodes HRESULTs automatically, so this specifier is not required in those cases.

0x00000000L, hr

S_OK

wc

Window class flag.

0x00000040, wc

WC_DEFAULTCHAR

wm

Windows message numbers

0x0010, wm

WM_CLOSE

!

raw format, ignoring any data type views customizations

i !

4

Size specifiers for pointers as arrays in Visual Studio 2012

If you have a pointer to an object you want to view as an array, you can use an integer or an expression to specify the number of array elements:

Specifier

Format

Expression

Value Displayed

n

Decimal or hexadecimal integer

pBuffer,[32]

pBuffer,[0x20]

Displays pBuffer as a 32 element array.

[exp]

A valid C++ expression that evaluates to an integer.

pBuffer,[bufferSize]

Evaluates bufferSize and displays pBuffer as an array of the evaluated number of elements.

expand(n)

pBuffer, expand(1,2)

Displays the third child of the second child of pBuffer

Format specifiers for interop debugging with C++/CLI or C++ edit and continue

Specifiers in bold are only supported for debugging native and C++/CLI code and debugging with C++ edit and continue.

Specifier

Format

Expression

Value Displayed

d,i

signed decimal integer

0xF000F065, d

-268373915

u

unsigned decimal integer

0x0065, u

101

o

unsigned octal integer

0xF065, o

0170145

x,X

Hexadecimal integer

61541, x

0x0000f065

l,h

long or short prefix for: d, i, u, o, x, X

00406042,hx

0x0c22

f

signed floating point

(3./2.), f

1.500000

e

signed scientific notation

(3./2.), e

1.500000e+000

g

signed floating point or signed scientific notation, whichever is shorter

(3./2.), g

1.5

c

Single character

0x0065, c

101 'e'

s

String

0x0012fde8, s

"Hello world"

su

Unicode string

0x0012fde8, su

L"Hello world"

sub

Unicode string

0x0012fde8, sub

Hello world

s8

UTF-8 string

0x0012fde8, s8

"Hello world"

hr

HRESULT or Win32 error code. (The debugger now decodes HRESULTs automatically, so this specifier is not required in those cases.

0x00000000L, hr

S_OK

wc

Window class flag.

0x00000040, wc

WC_DEFAULTCHAR

wm

Windows message numbers

0x0010, wm

WM_CLOSE

!

raw format, ignoring any data type views customizations

i !

4

Format specifiers memory locations in interop debugging with C++/CLI or C++ edit and continue

The following table contains formatting symbols used for memory locations. You can use a memory location specifier with any value or expression that evaluates to a location.

Symbol

Format

Expression

Value Displayed

ma

64 ASCII characters

ptr, ma

0x0012ffac .4...0...".0W&.......1W&.0.:W..1...."..1.JO&.1.2.."..1...0y....1

m

16 bytes in hexadecimal, followed by 16 ASCII characters

ptr, m

0x0012ffac B3 34 CB 00 84 30 94 80 FF 22 8A 30 57 26 00 00 .4...0...".0W&..

mb

16 bytes in hexadecimal, followed by 16 ASCII characters

ptr, mb

0x0012ffac B3 34 CB 00 84 30 94 80 FF 22 8A 30 57 26 00 00 .4...0...".0W&..

mw

8 words

ptr, mw

0x0012ffac 34B3 00CB 3084 8094 22FF 308A 2657 0000

md

4 doublewords

ptr, md

0x0012ffac 00CB34B3 80943084 308A22FF 00002657

mq

2 quadwords

ptr, mq

0x0012ffac 7ffdf00000000000 5f441a790012fdd4

mu

2-byte characters (Unicode)

ptr, mu

0x0012fc60 8478 77f4 ffff ffff 0000 0000 0000 0000

Size specifier for pointers as arrays in interop debugging with C++/CLI or C++ edit and continue

If you have a pointer to an object you want to view as an array, you can use an integer to specify the number of array elements:

Specifier

Format

Expression

Value Displayed

n

Decimal integer

pBuffer[32]

Displays pBuffer as a 32 element array.