String Conversion

This is a discussion on String Conversion within the C++ Programming forums, part of the General Programming Boards category; I am currently trying to convert a string that resides in a _bstr_t variable vFieldDate into a char array. I ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    27

    String Conversion

    I am currently trying to convert a string that resides in a _bstr_t variable vFieldDate into a char array. I have found that I can type cast this via the (char *) with a variable I named holder which is a pointer to a char. The issue I am having a hard time solving is how to convert this to a char that can be stored within the char Date[ARR]. When I attempt the following code I get the compilation error "Cannot Convert From Char * to Char. How do I extract the value that resides in the holder location and save it into the array?

    Date[cyc] = holder;

    The below portions of code are a part of an ADO program that is accessing data from a database.

    Code:
    char Date[ARR]     = {};
    _bstr_t                vFieldDate;
    vFieldDate           = rec->Fields->GetItem("Date")->Value;
    char *holder        = (char*)vFieldDate;

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    You can't copy to a char array using =.

    I've never worked with BSTR, but based on what I just read in MSDN library I think you should be able to use strcpy:

    Code:
    #include <cstring>
    //...
    strcpy( Date, holder );

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    27
    R.Stiltskin

    Excellent! It works great. Thank you for your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism and generic lists
    By Shibby3 in forum C# Programming
    Replies: 9
    Last Post: 07-26-2010, 06:27 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  5. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 04:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21