如何获取Cstring数组中的项目数 [英] How Do I Get The Number Of Items In Cstring Array

查看:203
本文介绍了如何获取Cstring数组中的项目数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;





我需要你的帮助,假设我有


CString h [500];





我希望得到这个数组中确切添加的项目数? br />


假设我只添加了123项,如何以编程方式计算



谢谢

hi;


I need your help in this, suppose I have

CString h[500];


and I want to get number of items exactly added in this array?

suppose I add only 123 items, how to get count programmatically

thanks

推荐答案

数组不会向开发人员公开它们的长度。您需要在某个对象中自己记住长度,并在需要时自行传递。

而不是这样的原始数组,您可以更好地使用一些MFC集合,具体取决于您的目标。请参阅:

https://msdn.microsoft.com/en-us /library/942860sh.aspx [ ^ ],

https://msdn.microsoft.com/en -us / library / y1z022s1.aspx [ ^ ]。



但是,我不确定你应该使用MFC数据对象,甚至不使用MFC字符串。如果你需要进行MFC UI开发,你可能会使用其中一些,但不知道是否是这种情况。



一般来说最好,您可以使用标准C ++(std ::)字符串和容器

http://www.cplusplus.com/reference/string/string [ ^ ],

http: //en.cppreference.com/w/cpp/string/basic_string [ ^ ],

http://www.cplusplus.com/ reference / stl [ ^ ],

http://en.cppreference.c om / w / cpp / container [ ^ ]。



-SA
Arrays don't expose their lengths to the developer. You need to remember the length by yourself in some object and pass it by yourself whenever it is required.
Instead of such "raw" array, you could better use some MFC collections, depending on your goals. Please see:
https://msdn.microsoft.com/en-us/library/942860sh.aspx[^],
https://msdn.microsoft.com/en-us/library/y1z022s1.aspx[^].

However, I'm not sure you should use MFC data objects at all, not even MFC strings. You could be bound to using some of them if they are required for MFC UI development you do, but don't know if this is the case or not.

Generally and preferably, you could use standard C++ ("std::") strings and containers:
http://www.cplusplus.com/reference/string/string[^],
http://en.cppreference.com/w/cpp/string/basic_string[^],
http://www.cplusplus.com/reference/stl[^],
http://en.cppreference.com/w/cpp/container[^].

—SA


更好的想法是使用https://msdn.microsoft.com/en-us/library/tddz3etf.aspx [ ^ ]。
A better idea would be to use https://msdn.microsoft.com/en-us/library/tddz3etf.aspx[^].


这篇关于如何获取Cstring数组中的项目数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆