如何获取Cstring数组中的项目数

编程入门 行业动态 更新时间:2024-10-28 11:20:03
本文介绍了如何获取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集合,具体取决于您的目标。请参阅: msdn.microsoft/en-us /library/942860sh.aspx [ ^ ], msdn.microsoft/en -us / library / y1z022s1.aspx [ ^ ]。 但是,我不确定你应该使用MFC数据对象,甚至不使用MFC字符串。如果你需要进行MFC UI开发,你可能会使用其中一些,但不知道是否是这种情况。 一般来说最好,您可以使用标准C ++(std ::)字符串和容器: www.cplusplus/reference/string/string [ ^ ], http: //en.cppreference/w/cpp/string/basic_string [ ^ ], www.cplusplus/ 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: msdn.microsoft/en-us/library/942860sh.aspx[^], msdn.microsoft/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: www.cplusplus/reference/string/string[^], en.cppreference/w/cpp/string/basic_string[^], www.cplusplus/reference/stl[^], en.cppreference/w/cpp/container[^].
—SA

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

更多推荐

如何获取Cstring数组中的项目数

本文发布于:2023-10-26 20:32:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531271.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组中   项目   Cstring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!