• Advertisement

Archived

This topic is now archived and is closed to further replies.

vector<char> to char*

This topic is 6527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there - Does anyone know how of an algorithm to convert a vector to a char*? Thanks all Emagen

Share this post


Link to post
Share on other sites
Advertisement
yes

char *string=new char[v.size()];
for(int i=0;i < v.size();i++)
. string=v[i];




Mike

Share this post


Link to post
Share on other sites
That doesn''t seem to work because it can''t convert a char to char*.

I need to append char to a char*, so I need to concatenate char to a char*.

Any ideas anyone?

thanks
Emagen

Share this post


Link to post
Share on other sites
First, I question the wisdom of using a vector. You seem to be wanting to have an array of characters, and you could do so with std::string.

As for the answer, you can try the copy algorithm
vector V(5);
char strArray[5];
copy(V.begin(), V.end(), strArray);
where the first parameter is source begin, followed by source end, and then strArray.

Please elaborate more as I do not really get what you need

Share this post


Link to post
Share on other sites
That seemed to work for what I wanted to do thanks a lot _dot_!

Emagen

Share this post


Link to post
Share on other sites
It messed up my code. That's supposed to be string [ i ] = v[ i ].


Mike

Edited by - Vetinari on 4/9/00 10:23:20 PM

Share this post


Link to post
Share on other sites

  • Advertisement