SSJBardock wrote:
please help me, I'm rewriting a program I made before because I lost
the source and I want to allocate a number of text strings that are
500 characters long.
So I tried this:
char *m_IDs[500]=(char *)malloc(m_NumberOfStrings);
That obviously doesn't work, but I can't remember how to do it.
std::vector<std::string> m_IDs(m_NumerOfStrings, std::string(500), ' ');
This creates a vector and initializes it with m_NumberOfStrings strings,
which are each initialized to 500 space characters.
If you insist on making your life hard by using arrays and pointers to
char:
char** m_IDs = new char*[m_NumberOfStrings];
for (int i = 0; i < m_NumberOfStrings; ++i)
m_IDs[i] = new char[500];
Note that those char arrays are uninitialized.
Don't forget to delete them:
for (int i = 0; i < m_NumberOfStrings; ++i)
delete [] m_IDs[i];
delete [] m_IDs;