C++ File Handling issue.

Hi Everyone

I have a test.tag file on disk. A small portion of the file is as follows:

<acc code = "SAVINGS" odate = "20090101">
<tag>Account Code</tag><val>SAVINGS</val>
<tag>Open Date</tag><val>01/01/2009</val>
</acc>

I have a C++ application which has a Parser class used to parse this tag file; code below

1
2
3
4
5
6
7
8
9
10
11
12
ifstream input(inputFileName);   // inputFileName is test.tag

class Parser
{
   ifstream& _input; // _input holds a reference to ifstream

   Parser(ifstream& infile) : _input(infile)

   // Other member functions and data used to read each line of test.tag and then parse it.
};

Parser obj(input); // Create the Parser object 


Now, i want to use the same Parser class but this time i have the file contents in memory (say char* poBuffer) instead of disk.
I would like to know which stream object sahould i create and how can i create the Parser object this time.
if the file contents are in memory why you need to stream it..
just manipulate it in the memory..
You want to use an istringstream.

It is quite common to do this in order to unit test classes.
Topic archived. No new replies allowed.