Field length and std::string - DICOM

This is a discussion on Field length and std::string - DICOM ; Hello, Before I dig into dcmtk code. Does anyone know if there is a way to use std::string while still handling string ending with '\0'. For instance when you read '1.2.840.10008.5.1.4.1.1.6.1'. This is an odd length string. So the dicom ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Field length and std::string

  1. Field length and std::string

    Hello,

    Before I dig into dcmtk code. Does anyone know if there is a way to use
    std::string while still handling string ending with '\0'.

    For instance when you read '1.2.840.10008.5.1.4.1.1.6.1'. This is an
    odd length string. So the dicom file adds a '\0'. But in my lib I store
    it as a std::string, so it automatically looses it \0.

    Any advice ?

    Thanks
    Mathieu


  2. Re: Field length and std::string

    Mathieu Malaterre wrote in message news:...
    > Hello,
    >
    > Before I dig into dcmtk code. Does anyone know if there is a way to use
    > std::string while still handling string ending with '\0'.
    >
    > For instance when you read '1.2.840.10008.5.1.4.1.1.6.1'. This is an
    > odd length string. So the dicom file adds a '\0'. But in my lib I store
    > it as a std::string, so it automatically looses it \0.
    >
    > Any advice ?
    >
    > Thanks
    > Mathieu


    //std::string can hold '\0'
    char test[50];
    memset(test,'a',sizeof(test));
    strcpy(test,"string contain 0");
    string s0(test,sizeof(test)-1);
    cout< cout<

  3. Re: Field length and std::string

    Mathieu Malaterre wrote:
    > Before I dig into dcmtk code. Does anyone know if there is a way to
    > use std::string while still handling string ending with '\0'.


    This should simply work. DCMTK handles the padding transparently to the
    user (and the padding is not always a \0). If you compile DCMTK with
    the macro HAVE_STD_STRING defined, then class OFString will actually be
    a typedef to std::string, offering you access methods to the dataset
    based on std::string.

    Regards,
    Marco Eichelberg
    OFFIS

  4. Re: Field length and std::string

    Marco Eichelberg wrote:
    > Mathieu Malaterre wrote:
    >
    >> Before I dig into dcmtk code. Does anyone know if there is a way
    >> to use std::string while still handling string ending with '\0'.

    >
    >
    > This should simply work. DCMTK handles the padding transparently to the
    > user (and the padding is not always a \0). If you compile DCMTK with
    > the macro HAVE_STD_STRING defined, then class OFString will actually be
    > a typedef to std::string, offering you access methods to the dataset
    > based on std::string.


    Thanks for your help. I also ask the question on comp.lang.c++ and they
    advice me to use:

    const char *s = "\0\0";
    std::string a(s,s+2); // will copy 2 '\0'

    -> a.size() == 2 as expected


    I tried it in my code, and I can 'assert' in a lot more places, that I
    always have read the proper number of characters.

    Mathieu


+ Reply to Thread