Though C++ problem...

Mavrick

Senior member
Mar 11, 2001
524
0
0
I have to build a program that reads the name of an XML data file on the command line, then opens that file and processes its data.

I have already done the function that can process the data, but I cannot get the program to open the file and store it in an "istream" stream (which is required). Here's what the main() looks like:

C:\>program.exe datafile.xml

int main( int argc, char *argv[] )
{
string FileName = argv[1];

***missing code to put the data in istream***

void processData( istream& inStream ){...}
return 0;
}
So, if anybody knows how to put the content of datafile.xml into inStream so it can be processed, that would really help me!!
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
What Nothingman is tersely getting at is that an istream (or actually an fstream) is what you get when you open the file. Then you use >> operator or get/getline/read to read the data from the file.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I was so terse because that's nearly the extent of my knowledge, I just so happened to be reading the file I/O section of GNU's libstdc++ documentation =)

My C++ skills are lacking and I'm trying to find something to cut my teeth on.
 

Mavrick

Senior member
Mar 11, 2001
524
0
0
Well, now, I can load the data in the stream, but the function processData(istream& inStream) still isn't able to take the stream as an argument.

Is there a way to give a name to the istream so I can pass it as an argument or is there another way? (As I understand it, the function needs an object inStream of class istream).
 

Mavrick

Senior member
Mar 11, 2001
524
0
0
Alright, I figured it out!!! :) I have to use "IN" as the argument variable.

Thanks!!
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
First, you're not really loading the data into the stream. The stream object is just a file handle. It doesn't actually contain the data.

You should have no trouble passing the stream object to the function though. What does your code look like now?
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: Mavrick
Alright, I figured it out!!! :) I have to use "IN" as the argument variable.

Thanks!!

LoL, yep, passing the variable name would be a good idea!
Glad to help.
 

Mavrick

Senior member
Mar 11, 2001
524
0
0
Originally posted by: ergeorge
First, you're not really loading the data into the stream. The stream object is just a file handle. It doesn't actually contain the data.

You should have no trouble passing the stream object to the function though. What does your code look like now?

Ooooh, ok. I wasn't really understanding why we use a stream instead of a string to store the file data up 'till now. But now I get it!! A stream is in fact just a kind of pointer between a input/output and a variable in the program/output device (screen, file).