How would I do an array of char*'s? i know that char* is an array of char's to make a string but what if I had an array of those? how would I write that?
Would it be:
char* [][]
of
char* []
or something else?
How would I do an array of char*'s? i know that char* is an array of char's to make a string but what if I had an array of those? how would I write that?
Would it be:
char* [][]
of
char* []
or something else?
Read it backwards.
It's an array of pointers to char. So yes, char *[] will be an array of char *'s.Code:char *[]
Easiest would be a vector of strings:
Or if you must use arrays:Code:#include <string> #include <vector> . . std::vector<std::string> myStrings;
Code:char myStrings[num_strings][length];
Some APIs require C-style strings, so therefore it's good to know how to use them in general. For regular usage, std::string should be used instead.
Hence "not recommended" but not "not necessary"
However, to some point I may agree, it usually only requires extracting buffers from std::string or CString and then also putting them back. It's not necessary to manipulate C-style strings outside string classes.
If an API needs a modifiable buffer, you need to create a dynamic C-String, copy the text over, send the buffer to the function, copy it back to a C++ string, and then free the memory. Practice doesn't hurt.
Nevertheless, as I said, std::string should be used in most circumstances.
A noteis also an array of strings equivalent to yourCode:char **except we're talking C style notations here.Code:char* []
A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside
Actually, it's char ** and char *[] is not quite equivalent. They may be used in a similar way SOMETIMES, e.g. if you want to allocate an array of pointers, you can return that as either type. But you can't make a char ** into a char *[] directly - you can the other way around.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.