You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
helpviewer_keywords: ["strings [C++], as function input/output", "argument passing [C++]", "arguments [C++], passing", "functions [C++], strings as input/output", "argument passing [C++], C strings", "passing arguments, C strings", "CString objects, passing arguments", "string arguments"]
6
-
ms.assetid: a67bebff-edf1-4cf4-bbff-d1cc6a901099
7
6
---
8
-
# CString Argument Passing
7
+
# `CString` Argument Passing
9
8
10
-
This article explains how to pass [CString](../atl-mfc-shared/reference/cstringt-class.md) objects to functions and how to return `CString` objects from functions.
9
+
This article explains how to pass [`CString`](../atl-mfc-shared/reference/cstringt-class.md) objects to functions and how to return `CString` objects from functions.
When you define a class interface, you must determine the argument-passing convention for your member functions. There are some standard rules for passing and returning `CString` objects. If you follow the rules described in [Strings as Function Inputs](#_core_strings_as_function_inputs) and [Strings as Function Outputs](#_core_strings_as_function_outputs), you will have efficient, correct code.
13
+
When you define a class interface, you must determine the argument-passing convention for your member functions. There are some standard rules for passing and returning `CString` objects. If you follow the rules described in [Strings as Function Inputs](#_core_strings_as_function_inputs) and [Strings as Function Outputs](#_core_strings_as_function_outputs), you'll have efficient, correct code.
15
14
16
15
## <aname="_core_strings_as_function_inputs"></a> Strings as Function Inputs
17
16
18
-
The most efficient and secure way to use a `CString` object in called functions is to pass a `CString` object to the function. Despite the name, a `CString` object does not store a string internally as a C-style string that has a null terminator. Instead, a `CString` object keeps careful track of the number of characters it has. Having `CString` provide a LPCTSTR pointer to a null-terminated string is a small amount of work that can become significant if your code has to do it constantly. The result is temporary because any change to the `CString` contents invalidates old copies of the LPCTSTR pointer.
17
+
The most efficient and secure way to use a `CString` object in called functions is to pass a `CString` object to the function. Despite the name, a `CString` object doesn't store a string internally as a C-style string that has a `NULL` terminator. Instead, a `CString` object keeps careful track of the number of characters it has. Having `CString` provide a `LPCTSTR` pointer to a `NULL`terminated string is a small amount of work that can become significant if your code has to do it constantly. The result is temporary because any change to the `CString` contents invalidates old copies of the `LPCTSTR` pointer.
19
18
20
-
It does make sense in some cases to provide a C-style string. For example, there can be a situation where a called function is written in C and does not support objects. In this case, coerce the `CString` parameter to LPCTSTR, and the function will get a C-style null-terminated string. You can also go the other direction and create a `CString` object by using the `CString` constructor that accepts a C-style string parameter.
19
+
It does make sense in some cases to provide a C-style string. For example, there can be a situation where a called function is written in C and doesn't support objects. In this case, coerce the `CString` parameter to `LPCTSTR`, and the function will get a C-style `NULL`terminated string. You can also go the other direction and create a `CString` object by using the `CString` constructor that accepts a C-style string parameter.
21
20
22
21
If the string contents are to be changed by a function, declare the parameter as a nonconstant `CString` reference (`CString&`).
An amount of time, which is internally stored as the number of seconds in the time span.
12
11
@@ -22,50 +21,50 @@ class CTimeSpan
22
21
23
22
|Name|Description|
24
23
|----------|-----------------|
25
-
|[CTimeSpan::CTimeSpan](#ctimespan)|Constructs `CTimeSpan` objects in various ways.|
24
+
|[`CTimeSpan::CTimeSpan`](#ctimespan)|Constructs `CTimeSpan` objects in various ways.|
26
25
27
26
### Public Methods
28
27
29
28
|Name|Description|
30
29
|----------|-----------------|
31
-
|[CTimeSpan::Format](#format)|Converts a `CTimeSpan` into a formatted string.|
32
-
|[CTimeSpan::GetDays](#getdays)|Returns a value that represents the number of complete days in this `CTimeSpan`.|
33
-
|[CTimeSpan::GetHours](#gethours)|Returns a value that represents the number of hours in the current day (-23 through 23).|
34
-
|[CTimeSpan::GetMinutes](#getminutes)|Returns a value that represents the number of minutes in the current hour (-59 through 59).|
35
-
|[CTimeSpan::GetSeconds](#getseconds)|Returns a value that represents the number of seconds in the current minute (-59 through 59).|
36
-
|[CTimeSpan::GetTimeSpan](#gettimespan)|Returns the value of the `CTimeSpan` object.|
37
-
|[CTimeSpan::GetTotalHours](#gettotalhours)|Returns a value that represents the total number of complete hours in this `CTimeSpan`.|
38
-
|[CTimeSpan::GetTotalMinutes](#gettotalminutes)|Returns a value that represents the total number of complete minutes in this `CTimeSpan`.|
39
-
|[CTimeSpan::GetTotalSeconds](#gettotalseconds)|Returns a value that represents the total number of complete seconds in this `CTimeSpan`.|
40
-
|[CTimeSpan::Serialize64](#serialize64)|Serializes data to or from an archive.|
30
+
|[`CTimeSpan::Format`](#format)|Converts a `CTimeSpan` into a formatted string.|
31
+
|[`CTimeSpan::GetDays`](#getdays)|Returns a value that represents the number of complete days in this `CTimeSpan`.|
32
+
|[`CTimeSpan::GetHours`](#gethours)|Returns a value that represents the number of hours in the current day (-23 through 23).|
33
+
|[`CTimeSpan::GetMinutes`](#getminutes)|Returns a value that represents the number of minutes in the current hour (-59 through 59).|
34
+
|[`CTimeSpan::GetSeconds`](#getseconds)|Returns a value that represents the number of seconds in the current minute (-59 through 59).|
35
+
|[`CTimeSpan::GetTimeSpan`](#gettimespan)|Returns the value of the `CTimeSpan` object.|
36
+
|[`CTimeSpan::GetTotalHours`](#gettotalhours)|Returns a value that represents the total number of complete hours in this `CTimeSpan`.|
37
+
|[`CTimeSpan::GetTotalMinutes`](#gettotalminutes)|Returns a value that represents the total number of complete minutes in this `CTimeSpan`.|
38
+
|[`CTimeSpan::GetTotalSeconds`](#gettotalseconds)|Returns a value that represents the total number of complete seconds in this `CTimeSpan`.|
39
+
|[`CTimeSpan::Serialize64`](#serialize64)|Serializes data to or from an archive.|
41
40
42
41
### Operators
43
42
44
43
|Name|Description|
45
44
|-|-|
46
-
|[operator + -](#operator_add_-)|Adds and subtracts `CTimeSpan` objects.|
47
-
|[operator += -=](#operator_add_eq_-_eq)|Adds and subtracts a `CTimeSpan` object to and from this `CTimeSpan`.|
48
-
|[operator == < etc.](#ctimespan_comparison_operators)|Compares two relative time values.|
45
+
|[`operator + -`](#operator_add_-)|Adds and subtracts `CTimeSpan` objects.|
46
+
|[`operator += -=`](#operator_add_eq_-_eq)|Adds and subtracts a `CTimeSpan` object to and from this `CTimeSpan`.|
47
+
|[`operator == < etc.`](#ctimespan_comparison_operators)|Compares two relative time values.|
49
48
50
49
## Remarks
51
50
52
-
`CTimeSpan`does not have a base class.
51
+
`CTimeSpan`doesn't have a base class.
53
52
54
53
`CTimeSpan` functions convert seconds to various combinations of days, hours, minutes, and seconds.
55
54
56
-
The `CTimeSpan` object is stored in a **__time64_t** structure, which is 8 bytes.
55
+
The `CTimeSpan` object is stored in a **`__time64_t`** structure, which is 8 bytes.
57
56
58
-
A companion class, [CTime](../../atl-mfc-shared/reference/ctime-class.md), represents an absolute time.
57
+
A companion class, [`CTime`](../../atl-mfc-shared/reference/ctime-class.md), represents an absolute time.
59
58
60
-
The `CTime` and `CTimeSpan` classes are not designed for derivation. Because there are no virtual functions, the size of both `CTime` and `CTimeSpan` objects is exactly 8 bytes. Most member functions are inline.
59
+
The `CTime` and `CTimeSpan` classes aren't designed for derivation. Because there are no virtual functions, the size of both `CTime` and `CTimeSpan` objects is exactly 8 bytes. Most member functions are inline.
61
60
62
61
For more information on using `CTimeSpan`, see the articles [Date and Time](../../atl-mfc-shared/date-and-time.md), and [Time Management](../../c-runtime-library/time-management.md) in the *Run-Time Library Reference*.
A formatting string similar to the `printf` formatting string. Formatting codes, preceded by a percent (`%`) sign, are replaced by the corresponding `CTimeSpan` component. Other characters in the formatting string are copied unchanged to the returned string. The value and meaning of the formatting codes for `Format` are listed below:
159
158
160
-
-**%D** Total days in this `CTimeSpan`
159
+
-**`%D`** Total days in this `CTimeSpan`
161
160
162
-
-**%H** Hours in the current day
161
+
-**`%H`** Hours in the current day
163
162
164
-
-**%M** Minutes in the current hour
163
+
-**`%M`** Minutes in the current hour
165
164
166
-
-**%S** Seconds in the current minute
165
+
-**`%S`** Seconds in the current minute
167
166
168
-
-**%%** Percent sign
167
+
-**`%%`** Percent sign
169
168
170
-
*nID*<br/>
169
+
*`nID`*\
171
170
The ID of the string that identifies this format.
172
171
173
172
### Return Value
@@ -176,13 +175,13 @@ A `CString` object that contains the formatted time.
176
175
177
176
### Remarks
178
177
179
-
The Debug version of the library checks the formatting codes and asserts if the code is not in the list above.
178
+
The Debug version of the library checks the formatting codes and asserts if the code isn't in the list above.
Returns a value that represents the number of complete days in this `CTimeSpan`.
188
187
@@ -196,13 +195,13 @@ Returns the number of complete 24-hour days in the time span. This value may be
196
195
197
196
### Remarks
198
197
199
-
Note that Daylight Savings Time can cause `GetDays` to return a potentially surprising result. For example, when DST is in effect, `GetDays` reports the number of days between April 1 and May 1 as 29, not 30, because one day in April is shortened by an hour and therefore does not count as a complete day.
198
+
Note that Daylight Savings Time (DST) can cause `GetDays` to return a potentially surprising result. For example, when DST is in effect, `GetDays` reports the number of days between April 1 and May 1 as 29, not 30, because one day in April is shortened by an hour and therefore doesn't count as a complete day.
0 commit comments