CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 1999
    Posts
    8

    string conversion to vector<char>

    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

  2. #2
    Join Date
    Jul 1999
    Posts
    8

    Re: string conversion to vector<char>

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured