I have created an array:
CString* pstrArray = new CString[nMySize];
Now how can I pass it to a function to be filled up? What is the actual parameter?
void FillThisArray(what goes here?)
{
}
You should use a container class: CStringArray
void FillThisArray( CStringArray & rMyStrings )
If you don't want this (I don't see any possible reason, but anyway):
void FillThisArray(CString* strings, size_t num)
{
// example
for( size_t s=0; s<num; s++ )
{
strings[s].Format( _T("This is the %d. string"), s+1 );
}
}
CString* pstrArray = NULL; pstrArray = new CString[nMySize];
For simplicity:
CString* pstrArray = new CString[nMySize];
Now how can i pass it to a function to be filled up? What is the actual parameter?
void FillThisArray(????) { }
The most obvious interface is:
void FillThisArray(CString* pstrArray, size_t n)
Taking a step back:
CString
s will be allocated by that single new statementstd::vector<std::string>
std::vector
because:
push_back()
, and in such usage can grow beyond the initial size without any special work on your partvector
if you really want that behaviourstd::string
because:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With