VC++中如何实现字符串数组?

要用CString如何构建?不想通过传统的char字符实现数组
另外,请介绍CStringArray详细用法,我手头没MSDN,非常急!
最新回答
朵朵奇葩向阳开#

2024-04-21 00:27:36

CString类:
用GetString(数组只读时用)和GetBuffer(向数组写数据时用,GetBuffer无参数)来获得CString内保存的数组,

当GetBuffer有参数时(int型)为分配指定大小的数组(但用GetLength好象不能获得字符串的长度).

下面是把CStringArray的函数说明复制下来的(原文,英文我看不明白,你自己看吧).
Base Class Members

CObject Members

CStringArray Members

Construction

CStringArray Constructs an empty array for CString objects.

Bounds

GetCount Gets number of elements in this array.
GetSize Gets number of elements in this array.
GetUpperBound Returns the largest valid index.
SetSize Sets the number of elements to be contained in this array.

Operations

FreeExtra Frees all unused memory above the current upper bound.
RemoveAll Removes all the elements from this array.

Element Access

ElementAt Returns a temporary reference to the element pointer within the array.
GetAt Returns the value at a given index.
GetData Allows access to elements in the array. Can be NULL.
SetAt Sets the value for a given index; array not allowed to grow.

Growing the Array

Add Adds an element to the end of the array; grows the array if necessary.
Append Appends another array to the array; grows the array if necessary.
Copy Copies anolther array to the array; grows the array if necessary.
SetAtGrow Sets the value for a given index; grows the array if necessary.

Insertion/Removal

InsertAt Inserts an element (or all the elements in another array) at a specified index.
IsEmpty Determines if the array is empty
RemoveAt Removes an element at a specific index.

Operators

operator [] Sets or gets the element at the specified index.

See Also
CStringArray Overview | Hierarchy Chart

--------------------------------------------------------------------------------

Send feedback on this topic to Microsoft

© Microsoft Corporation. All rights reserved.
生生漫

2024-04-21 00:24:13

CString cs;
cs.GetAt(i);