Skip to content

Repo sync for protected CLA branch #3430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 80 additions & 26 deletions docs/atl-mfc-shared/reference/csimplestringt-class.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
---
description: "Learn more about: CSimpleStringT Class"
title: "CSimpleStringT Class"
ms.date: "10/18/2018"
ms.date: 10/04/2021
f1_keywords: ["CSimpleStringT", "ATLSIMPSTR/ATL::CSimpleStringT", "ATLSIMPSTR/ATL::CSimpleStringT::PCXSTR", "ATLSIMPSTR/ATL::CSimpleStringT::PXSTR", "ATLSIMPSTR/ATL::CSimpleStringT::CSimpleStringT", "ATLSIMPSTR/ATL::CSimpleStringT::Append", "ATLSIMPSTR/ATL::CSimpleStringT::AppendChar", "ATLSIMPSTR/ATL::CSimpleStringT::CopyChars", "ATLSIMPSTR/ATL::CSimpleStringT::CopyCharsOverlapped", "ATLSIMPSTR/ATL::CSimpleStringT::Empty", "ATLSIMPSTR/ATL::CSimpleStringT::FreeExtra", "ATLSIMPSTR/ATL::CSimpleStringT::GetAllocLength", "ATLSIMPSTR/ATL::CSimpleStringT::GetAt", "ATLSIMPSTR/ATL::CSimpleStringT::GetBuffer", "ATLSIMPSTR/ATL::CSimpleStringT::GetBufferSetLength", "ATLSIMPSTR/ATL::CSimpleStringT::GetLength", "ATLSIMPSTR/ATL::CSimpleStringT::GetManager", "ATLSIMPSTR/ATL::CSimpleStringT::GetString", "ATLSIMPSTR/ATL::CSimpleStringT::IsEmpty", "ATLSIMPSTR/ATL::CSimpleStringT::LockBuffer", "ATLSIMPSTR/ATL::CSimpleStringT::Preallocate", "ATLSIMPSTR/ATL::CSimpleStringT::ReleaseBuffer", "ATLSIMPSTR/ATL::CSimpleStringT::ReleaseBufferSetLength", "ATLSIMPSTR/ATL::CSimpleStringT::SetAt", "ATLSIMPSTR/ATL::CSimpleStringT::SetManager", "ATLSIMPSTR/ATL::CSimpleStringT::SetString", "ATLSIMPSTR/ATL::CSimpleStringT::StringLength", "ATLSIMPSTR/ATL::CSimpleStringT::Truncate", "ATLSIMPSTR/ATL::CSimpleStringT::UnlockBuffer"]
helpviewer_keywords: ["shared classes, CSimpleStringT", "strings [C++], ATL class", "CSimpleStringT class"]
ms.assetid: 15814fcb-5b8f-4425-a97e-3b61fc9b48d8
---
# `CSimpleStringT` Class

This class represents a `CSimpleStringT` object.

## Syntax

```
```cpp
template <typename BaseType>
class CSimpleStringT
```
Expand Down Expand Up @@ -122,6 +121,8 @@ Call this method to append an existing `CSimpleStringT` object to another `CSimp
The following example demonstrates the use of `CSimpleStringT::Append`.

```cpp
CAtlString basestr;
IAtlStringMgr* pMgr = basestr.GetManager();
CSimpleString str1(pMgr), str2(pMgr);
str1.SetString(_T("Soccer is"));
str2.SetString(_T(" an elegant game"));
Expand Down Expand Up @@ -154,7 +155,7 @@ Copies a character or characters to a `CSimpleStringT` object.

### Syntax

```
```cpp
static void CopyChars(
XCHAR* pchDest,
const XCHAR* pchSrc,
Expand All @@ -181,20 +182,29 @@ Call this method to copy characters from *`pchSrc`* to the *`pchDest`* string.
The following example demonstrates the use of `CSimpleStringT::CopyChars`.

```cpp
CAtlString basestr;
IAtlStringMgr* pMgr = basestr.GetManager();
CSimpleString str(_T("xxxxxxxxxxxxxxxxxxx"), 20, pMgr);
TCHAR* pszSrc = _T("Hello world!");
const TCHAR* pszSrc = _T("Hello world!");
_tprintf_s(_T("%s\n"), str);
str.CopyChars(str.GetBuffer(), pszSrc, 12);
str.CopyChars(str.GetBuffer(), 20, pszSrc, 12);
_tprintf_s(_T("%s\n"), str);
```

The output from this example is as follows:

```output
xxxxxxxxxxxxxxxxxxx
Hello world!xxxxxxx
```

## <a name="copycharsoverlapped"></a> `CSimpleStringT::CopyCharsOverlapped`

Copies a character or characters to a `CSimpleStringT` object.

### Syntax

```
```cpp
static void CopyCharsOverlapped(
XCHAR* pchDest,
const XCHAR* pchSrc,
Expand Down Expand Up @@ -226,7 +236,7 @@ Constructs a `CSimpleStringT` object.

### Syntax

```
```cpp
CSimpleStringT(const XCHAR* pchSrc, int nLength, IAtlStringMgr* pStringMgr);
CSimpleStringT(PCXSTR pszSrc, IAtlStringMgr* pStringMgr);
CSimpleStringT(const CSimpleStringT& strSrc);
Expand Down Expand Up @@ -259,6 +269,9 @@ Construct a new `CSimpleStringT` object. Because the constructors copy the input
The following example demonstrates the use of `CSimpleStringT::CSimpleStringT` by using the ATL **`typedef`** `CSimpleString`. `CSimpleString` is a commonly used specialization of the class template `CSimpleStringT`.

```cpp
CAtlString basestr;
IAtlStringMgr* pMgr = basestr.GetManager();

CSimpleString s1(pMgr);
// Empty string
CSimpleString s2(_T("cat"), pMgr);
Expand Down Expand Up @@ -292,6 +305,9 @@ For more information, see [Strings: `CString` Exception Cleanup](../cstring-exce
The following example demonstrates the use of `CSimpleStringT::Empty`.

```cpp
CAtlString basestr;
IAtlStringMgr* pMgr = basestr.GetManager();

CSimpleString s(pMgr);
ASSERT(s.IsEmpty());
```
Expand Down Expand Up @@ -351,7 +367,7 @@ Retrieves the allocated length of a `CSimpleStringT` object.

### Syntax

```
```cpp
int GetAllocLength() const throw();
```

Expand All @@ -369,7 +385,7 @@ Returns one character from a `CSimpleStringT` object.

### Syntax

```
```cpp
XCHAR GetAt(int iChar) const;
```

Expand Down Expand Up @@ -401,7 +417,7 @@ Returns a pointer to the internal character buffer for the `CSimpleStringT` obje

### Syntax

```
```cpp
PXSTR GetBuffer(int nMinBufferLength);
PXSTR GetBuffer();
```
Expand Down Expand Up @@ -450,7 +466,7 @@ Returns a pointer to the internal character buffer for the `CSimpleStringT` obje

### Syntax

```
```cpp
PXSTR GetBufferSetLength(int nLength);
```

Expand Down Expand Up @@ -507,7 +523,7 @@ Returns the number of characters in the `CSimpleStringT` object.

### Syntax

```
```cpp
int GetLength() const throw();
```

Expand All @@ -527,7 +543,7 @@ Retrieves the memory manager of the `CSimpleStringT` object.

### Syntax

```
```cpp
IAtlStringMgr* GetManager() const throw();
```

Expand All @@ -545,7 +561,7 @@ Retrieves the character string.

### Syntax

```
```cpp
PCXSTR GetString() const throw();
```

Expand All @@ -565,18 +581,26 @@ Call this method to retrieve the character string associated with the `CSimpleSt
The following example demonstrates the use of `CSimpleStringT::GetString`.

```cpp
CAtlString basestr;
IAtlStringMgr* pMgr = basestr.GetManager();
CSimpleString str(pMgr);
str += _T("Cup soccer is best!");
_tprintf_s(_T("%s"), str.GetString());
```

The output from this example is as follows:

```output
Cup soccer is best!
```

## <a name="isempty"></a> `CSimpleStringT::IsEmpty`

Tests a `CSimpleStringT` object for the empty condition.

### Syntax

```
```cpp
bool IsEmpty() const throw();
```

Expand All @@ -603,7 +627,7 @@ Disables reference counting and protects the string in the buffer.

### Syntax

```
```cpp
PXSTR LockBuffer();
```

Expand Down Expand Up @@ -639,6 +663,9 @@ For more information about reference counting, see the following articles:
The following example demonstrates the use of `CSimpleStringT::LockBuffer`.

```cpp
CAtlString basestr;
IAtlStringMgr* pMgr = basestr.GetManager();

CSimpleString str(_T("Hello"), pMgr);
TCHAR ch;

Expand All @@ -648,13 +675,19 @@ _tprintf_s(_T("%c"), ch);
str.UnlockBuffer();
```

The output from this example is as follows:

```output
l
```

## <a name="operator_at"></a> `CSimpleStringT::operator[]`

Call this function to access a single character of the character array.

### Syntax

```
```cpp
XCHAR operator[](int iChar) const;
```

Expand Down Expand Up @@ -685,7 +718,7 @@ Call this function to access a single character of the character array.

### Syntax

```
```cpp
XCHAR operator[](int iChar) const;
```

Expand All @@ -707,7 +740,7 @@ Joins a new string or character to the end of an existing string.

### Syntax

```
```cpp
CSimpleStringT& operator +=(PCXSTR pszSrc);
CSimpleStringT& operator +=(const CSimpleStringT& strSrc);
template<int t_nSize>
Expand Down Expand Up @@ -747,7 +780,7 @@ Assigns a new value to a `CSimpleStringT` object.

### Syntax

```
```cpp
CSimpleStringT& operator =(PCXSTR pszSrc);
CSimpleStringT& operator =(const CSimpleStringT& strSrc);
```
Expand Down Expand Up @@ -794,7 +827,7 @@ Directly accesses characters stored in a `CSimpleStringT` object as a C-style st

### Syntax

```
```cpp
operator PCXSTR() const throw();
```

Expand Down Expand Up @@ -846,7 +879,7 @@ A pointer to a constant string.

### Syntax

```
```cpp
typedef ChTraitsBase< BaseType >::PCXSTR PCXSTR;
```

Expand Down Expand Up @@ -876,19 +909,29 @@ Call this method to allocate a specific buffer size for the `CSimpleStringT` obj
The following example demonstrates the use of `CSimpleStringT::Preallocate`.

```cpp
CAtlString basestr;
IAtlStringMgr* pMgr = basestr.GetManager();

CSimpleString str(pMgr);
_tprintf_s(_T("Allocated length: %d\n"), str.GetAllocLength());
str.Preallocate(100);
_tprintf_s(_T("Allocated length: %d\n"), str.GetAllocLength());
```

The output from this example is as follows:

```output
Allocated length: 0
Allocated length: 103
```

## <a name="pxstr"></a> `CSimpleStringT::PXSTR`

A pointer to a string.

### Syntax

```
```cpp
typedef ChTraitsBase< BaseType >::PXSTR PXSTR;
```

Expand Down Expand Up @@ -1060,7 +1103,7 @@ Returns the number of characters in the specified string.

### Syntax

```
```cpp
ATL_NOINLINE static int StringLength(PCXSTR psz) throw();
```

Expand Down Expand Up @@ -1112,6 +1155,8 @@ Call this method to truncate the contents of the string to the new length.
The following example demonstrates the use of `CSimpleStringT::Truncate`.

```cpp
CAtlString basestr;
IAtlStringMgr* pMgr = basestr.GetManager();
CSimpleString str(_T("abcdefghi"), pMgr);
_tprintf_s(_T("Allocated length: %d\n"), str.GetLength());
_tprintf_s(_T("Contents: %s\n"), str);
Expand All @@ -1120,6 +1165,15 @@ _tprintf_s(_T("Allocated length: %d\n"), str.GetLength());
_tprintf_s(_T("Contents: %s\n"), str);
```

The output from this example is:

```Output
Allocated length: 9
Contents: abcdefghi
Allocated length: 4
Contents: abcd
```

## <a name="unlockbuffer"></a> `CSimpleStringT::UnlockBuffer`

Unlocks the buffer of the `CSimpleStringT` object.
Expand All @@ -1142,7 +1196,7 @@ Destroys a `CSimpleStringT` object.

### Syntax

```
```cpp
~CSimpleStringT() throw();
```

Expand Down
2 changes: 1 addition & 1 deletion docs/c-runtime-library/reference/rand.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int rand(void);

The **`rand`** function returns a pseudorandom integer in the range 0 to **`RAND_MAX`** (32767). Use the [`srand`](srand.md) function to seed the pseudorandom-number generator before calling **`rand`**.

The **`rand`** function generates a well-known sequence and isn't appropriate for use as a cryptographic function. For more cryptographically secure random number generation, use [`rand_s`](rand-s.md) or the functions declared in the C++ Standard Library in [`<random>`](../../standard-library/random.md). For information about what's wrong with **`rand`** and how `<random>` addresses these shortcomings, see this video entitled [rand Considered Harmful](https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful).
The **`rand`** function generates a well-known sequence and isn't appropriate for use as a cryptographic function. For more cryptographically secure random number generation, use [`rand_s`](rand-s.md) or the functions declared in the C++ Standard Library in [`<random>`](../../standard-library/random.md).

By default, this function's global state is scoped to the application. To change this, see [Global state in the CRT](../global-state.md).

Expand Down
4 changes: 0 additions & 4 deletions docs/cpp/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ landingContent:
url: ../build/vscpp-step-1-create.md
- text: Create a console calculator in C++
url: ../get-started/tutorial-console-cpp.md
- linkListType: video
links:
- text: "Learn C++ - A general purpose language and library"
url: https://channel9.msdn.com/Series/cplusplus-language-library
- linkListType: learn
links:
- text: Welcome back to C++ - Modern C++
Expand Down
Loading