468,512 Members | 1,369 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Dynamic allocate string array

Hi,

I have a char * mFileList[];

how can i dynamically allocate it to save some strings?

Thanks in advance
Feb 28 '08 #1
7 6700
On Feb 28, 2:53 pm, huohaod...@gmail.com wrote:
Hi,

I have a char * mFileList[];

how can i dynamically allocate it to save some strings? I'd like to allocate it to and array of POINTERS to char strings, some thing like char *mFileList[1000]

Thanks in advance
Feb 28 '08 #2
hu********@gmail.com wrote:
I have a char * mFileList[];

how can i dynamically allocate it to save some strings?
std::vector<std::stringmFileList;

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 28 '08 #3
On Feb 28, 3:12 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
huohaod...@gmail.com wrote:
I have a char * mFileList[];
how can i dynamically allocate it to save some strings?

std::vector<std::stringmFileList;

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I tried char * mFileList[] = new char[index]; but got a syntax error.
Feb 28 '08 #4
hu********@gmail.com wrote:
[..]
I tried char * mFileList[] = new char[index]; but got a syntax error.
char **mFileList = new char*[size];

But let me reiterate, do NOT presume managing dynamic memory is
easy or recommended. Try to stick to standard containers before
you learn enough. Do

std::vector<std::stringmFileList(size);

It's basically all you need, trust me.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 28 '08 #5
On Feb 28, 3:46 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
huohaod...@gmail.com wrote:
[..]
I tried char * mFileList[] = new char[index]; but got a syntax error.

char **mFileList = new char*[size];

But let me reiterate, do NOT presume managing dynamic memory is
easy or recommended. Try to stick to standard containers before
you learn enough. Do

std::vector<std::stringmFileList(size);

It's basically all you need, trust me.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks a lot for the help
Feb 28 '08 #6
hu********@gmail.com wrote:
Hi,

I have a char * mFileList[];
This is an invalid declaration. You must either have an initializer
list or give that array a dimension.
how can i dynamically allocate it to save some strings?
Do what Victor said. Use the tools that have been developed to aid the
programmer.


Brian
Feb 28 '08 #7
hu********@gmail.com wrote:
Hi,

I have a char * mFileList[];

how can i dynamically allocate it to save some strings?

Thanks in advance
If possible, try std::vector<std::stringmFileList;
If not possible, try std::vector<char*mFileList;

The std::vector should be as effective as anything manaul, such as new
char*[count] and with a known value you can do:

std::vector<char*mFileList( count );
Which will create a dynamic array of count elements of char*.

Still, std::vector<std::stringis much prefered, but it really depeneds on
your code.
--
Jim Langston
ta*******@rocketmail.com
Feb 29 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Peter B. Steiger | last post: by
6 posts views Thread by Materialised | last post: by
11 posts views Thread by D | last post: by
2 posts views Thread by Richard | last post: by
12 posts views Thread by googlinggoogler | last post: by
8 posts views Thread by omariqbalnaru | last post: by
3 posts views Thread by sunilkjin | last post: by
6 posts views Thread by Paul | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.