Click to See Complete Forum and Search --> : string conversion to vector<char>


vtMoose
July 9th, 1999, 12:19 PM
Hey all...

I'm encountering a casting style problem that I'm not able to find a good way around.

Currently, I have something that looks like this

istream_iterator&lt;string&gt; string_input;

this iterator works great when I'm reading my input file, but later I use it to grab input from
the console as such

string_input j(cin);

however, I want to convert the contents of j into
a vector&lt;char&gt; container, according to the book
I'm using, string provides a conversion to vector&lt;char&gt;. So I issue one of these..

vector&lt;char&gt; lookup = *j;

During compiling, I get an error that basically states, cannot convert from const basic_string&lt;..&gt; to vector&lt;char....&gt;. My book states the conversion is possible, however, the compiler says no.

Why?


I drank what? - Socrates

Contact me via ICQ - 23239270

vtMoose
July 9th, 1999, 04:11 PM
I found my answer, so I thought I'd post it in case anyone is curious! =)

apparently,
vector&lt;char&gt; vector1 = string("Poop");

is not valid, although it's used frequently in my reference book, (however, they are using a bstring.h library that I'm not because it wouldn't compile under vs 6.0).

what was suggested to me was to use..

stirng s("Poop");
vector&lt;char&gt; vector1(s.begin(),s.end());

that seems to do the trick =)



I drank what? - Socrates

Contact me via ICQ - 23239270