Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Convert string to stream?

Reply
Thread Tools

Convert string to stream?

 
 
Casper Bang
Guest
Posts: n/a
 
      09-25-2003
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


 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      09-25-2003

"Casper Bang" <> wrote in message
news:3f731a2b$0$54828$ k...
> 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


 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      09-26-2003
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert formatted string to string? rockdale ASP .Net 3 04-12-2006 03:01 PM
convert string to the "escaped string" Petr Jakes Python 3 11-12-2005 05:32 PM
convert string to raw string? Phd Python 3 12-06-2004 04:36 PM
Connection String object Convert to String Variable Type =?Utf-8?B?TWlrZSBNb29yZQ==?= ASP .Net 2 10-26-2004 02:43 PM
Convert string to a string array Andrew Banks ASP .Net 2 04-19-2004 04:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57