Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Richard MacCutchan 29-Apr-15 13:59pm    
You have to add some code to count them.
CPallini 29-Apr-15 15:35pm    
Arrays don't provide such bookkeeping, you have to implement yourself (or use a container class).

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
 
Share this answer
 
Comments
CPallini 29-Apr-15 15:34pm    
5.Yes, expecially C++ standard library containers are much better than MFC ones.
Sergey Alexandrovich Kryukov 29-Apr-15 15:44pm    
Thank you, Carlo.
—SA
 
Share this answer
 
Comments
CPallini 29-Apr-15 15:34pm    
True, 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900