Convert string to stream?

Discussion in 'C++' started by Casper Bang, Sep 25, 2003.

  1. Casper Bang

    Casper Bang Guest

    I am using an older C library (Flex scanner) which requires that a variable
    is set as a pointer to a file:

    #define FILE _iobuf
    FILE* hFile;

    It works great but I would like to add a wrapper so I can parse a string in
    memmory as well. Presently I do that by saving the string in a temp file and
    then making the original call to the library with the filehandle. This is
    slow and clumsy so I was wondering if there's some way of converting a
    string to an appropiate stream (or _iobuf whatever that is)?

    Thanks in advance,
    Casper
     
    Casper Bang, Sep 25, 2003
    #1
    1. Advertising

  2. Casper Bang

    Mike Wahler Guest

    "Casper Bang" <> wrote in message
    news:3f731a2b$0$54828$...
    > I am using an older C library (Flex scanner) which requires that a

    variable
    > is set as a pointer to a file:
    >
    > #define FILE _iobuf
    > FILE* hFile;



    '_iobuf' is a name which is reserved to the implementation.
    Do not use it in your code. Same goes for 'FILE'.

    Use #include <stdio.h> to get the proper defintion
    of 'FILE' for your implementation.

    #include <stdio.h>

    FILE *hFile;

    >
    > It works great but I would like to add a wrapper so I can parse a string

    in
    > memmory as well. Presently I do that by saving the string in a temp file

    and
    > then making the original call to the library with the filehandle. This is
    > slow and clumsy so I was wondering if there's some way of converting a
    > string to an appropiate stream (or _iobuf whatever that is)?


    I suppose you found that 'io_buf' by looking at header file(s).
    It's an implementation detail -- hands off to the application
    programmer. #include <stdio.h> and use 'FILE *'.

    There's no standard way to do what you want.

    -Mike
     
    Mike Wahler, Sep 25, 2003
    #2
    1. Advertising

  3. Casper Bang

    Jerry Coffin Guest

    In article <3f731a2b$0$54828$>,
    says...
    > I am using an older C library (Flex scanner) which requires that a variable
    > is set as a pointer to a file:
    >
    > #define FILE _iobuf
    > FILE* hFile;
    >
    > It works great but I would like to add a wrapper so I can parse a string in
    > memmory as well.


    A Flex scanner will normally use YY_INPUT to get input. You can define
    that yourself if you want it to read data in a different fashion than
    the usual.

    > Presently I do that by saving the string in a temp file and
    > then making the original call to the library with the filehandle. This is
    > slow and clumsy so I was wondering if there's some way of converting a
    > string to an appropiate stream (or _iobuf whatever that is)?


    It's OS specific, but in quite a few cases you could also create a pipe
    and have it read from the pipe, while something at the other end feeds
    the data from the string into the pipe. This would be useful if the
    scanner itself needed to be oblivious to the source of the data.

    Flex also supports a '-+' argument to create a C++ lexer as a set of
    classes. In this case, the lexer class reads from an istream so it
    should be quite easy to pass an istringstream instead.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
     
    Jerry Coffin, Sep 26, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmusson, Lars
    Replies:
    1
    Views:
    776
    popov
    Apr 30, 2004
  2. Titus Barik

    convert string to input stream

    Titus Barik, Aug 31, 2004, in forum: Python
    Replies:
    2
    Views:
    3,016
    Alex Martelli
    Sep 1, 2004
  3. Replies:
    9
    Views:
    664
    Alex Buell
    Apr 27, 2006
  4. Manuel
    Replies:
    7
    Views:
    675
    Default User
    Sep 12, 2006
  5. Alexander Korsunsky

    get stream mode flags from an opened stream

    Alexander Korsunsky, Feb 17, 2007, in forum: C++
    Replies:
    1
    Views:
    468
    John Harrison
    Feb 17, 2007
Loading...

Share This Page