vector<char> to char*

Started by
4 comments, last by Emagen 24 years ago
Hi there - Does anyone know how of an algorithm to convert a vector to a char*? Thanks all Emagen
Advertisement
yes

char *string=new char[v.size()];
for(int i=0;i < v.size();i++)
. string=v;<br><br><br><br><br>Mike </i>
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown
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
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
That seemed to work for what I wanted to do thanks a lot _dot_!

Emagen
It messed up my code. That's supposed to be string = v.<br><br><br>Mike <br><br>Edited by - Vetinari on 4/9/00 10:23:20 PM
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown

This topic is closed to new replies.

Advertisement