CStringArray Class
2015-12-06 22:23
260 查看
CStringArray : CObject
The CStringArray class supports arrays of CString objects.The member functions of CStringArray are similar to the member functions of class
CObArray. Because of this similarity, you can use the
CObArray reference documentation for member function specifics. Wherever you see a
CObject pointer as a return value, substitute a CString (not a
CString pointer). Wherever you see a CObject pointer as a function parameter, substitute a
LPCTSTR.
CObject* CObArray::GetAt( int <nIndex> ) const;
for example, translates to
CString CStringArray::GetAt( int <nIndex> ) const;
and
void SetAt( int <nIndex>, CObject* <newElement> )
translates to
void SetAt( int <nIndex>, LPCTSTR <newElement> )
CStringArray incorporates the IMPLEMENT_SERIAL macro to support serialization and dumping of its elements. If an array of
CString objects is stored to an archive, either with an overloaded insertion operator or with the
Serialize member function, each element is serialized in turn.
Note Before using an array, use SetSize to establish its size and allocate memory for it. If you do not use
SetSize, adding elements to your array causes it to be frequently reallocated and copied. Frequent reallocation and copying are inefficient and can fragment memory.
If you need a dump of individual string elements in the array, you must set the depth of the dump context to 1 or greater.
When a CString array is deleted, or when its elements are removed, string memory is freed as appropriate.
For more information on using CStringArray, see the articleCollections in
Visual C++ Programmer’s Guide.
#include <afxcoll.h>
CStringArray Class Members
ConstructionCStringArray | Constructs an empty array for CString objects. |
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. |
FreeExtra | Frees all unused memory above the current upper bound. |
RemoveAll | Removes all the elements from this array. |
GetAt | Returns the value at a given index. |
SetAt | Sets the value for a given index; array not allowed to grow. |
ElementAt | Returns a temporary reference to the element pointer within the array. |
GetData | Allows access to elements in the array. Can be NULL. |
SetAtGrow | Sets the value for a given index; grows the array if necessary. |
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. |
InsertAt | Inserts an element (or all the elements in another array) at a specified index. |
RemoveAt | Removes an element at a specific index. |
operator [] | Sets or gets the element at the specified index. |
CString strPath = "F:\\VBA\\*.*";
CString strFileName;
CStringArray strResult;
strResult.RemoveAll(); //文件列表清空
CFileFind finder;
BOOL bWorking = finder.FindFile(strPath);
while (bWorking)
{
bWorking = finder.FindNextFile();
if(finder.IsDirectory()) //若确定找到的文件是否是一个目录,结束本次循环。
continue;
strFileName = finder.GetFileName();
//cout << (LPCTSTR)strFileName << endl;
strResult.Add(strFileName);
}
finder.Close();
int iCount = strResult.GetSize();
if(iCount > 0)
{
int i;
for(i = 0;i < iCount;i++)
{
cout << (LPCTSTR)strResult.GetAt(i) << "\n";
}
cout << "最大索引是:" << strResult.GetUpperBound() << "\n";
cout << "元素总数是:" << strResult.GetSize() << "\n";
system("pause");
}
else
{
;
}
相关文章推荐
- hpuoj 1723: 感恩节KK专场——陪学妹上课 (模拟&规律)
- JVM读书笔记
- 青菜(小白菜)
- Remove Duplicates from Sorted Array
- eclipse常用调试
- Container With Most Water
- 如何保护手机号码泄露隐私
- 如何保护手机号码泄露隐私
- 线程与进程的区别
- 读代码大全2——第四章 关键的“构建”决策
- Python解析已下载html文件
- Subsets,Subsets II
- hdoj 5533 Dancing Stars on Me 【数学题】
- ios UISearchDisplayController 实现 UITableView 搜索功能
- SpringMVC_上传图片
- IOS--文件存储
- sql内连接与外连接的用法
- java 泛型问题 关于警告XXX is a raw type
- window.open的兼容性问题
- 关于编程语言的思考——编译型和解释型