Dev-C++ help

mosdef

Banned
May 14, 2000
2,253
0
0
I want to be able to pass an input file into the program, and have the output written to an output file in Dev-C++. In unix, it would be equivalent to writing

% a.out < inputfile > outputfile

Any help? Thanks!

-mosdef
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Dev-C++? Not sure of the significance, as I've never heard of it. Are you wanting to know how to process files, or are you wanting to know how to process the arguments? How you process the files is largely up to you (whether you're on Unix, Win32 and decide to use the Win32 api for the file processing, or the standard C++ method). Processing arguments would be as simple as:

int main(int argc, char **argv)
{
char *ifile = NULL, *ofile = NULL;
if (argc == 3)
{
// we'd want to do more validation here, but lets assume they used the correct arguments
ifile = argv[1];
ofile = argv[2];
}
else
usage(); // or something

return 0;
}

Not sure if this is what you wanted, but if you answer my questions above, we can discuss the other methods for processing files.
 

mosdef

Banned
May 14, 2000
2,253
0
0
Dev-C++ is a free IDE for C++ for Windows. A great program if you ask me! Anyway, I think I worded my question incorrectly. I want to pipe in/out data. If you are familiar with Unix, you might know about piping. Basically, I write a program, and it is going to expect certain input from the user. Well I can create a text file with the data in advance so I don't have to keep retyping it for debugging purposes. The same goes for outputting to a file instead of to the screen, which makes debugging easier. I have no interest in reading from a file / writing to a file within the actual C++ code but rather from the command line. What I want to do is completely dependant on the software, not the code I am writing. I just can't figure out where the option to do this is.

-mosdef
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
In that case, you simply need to read from stdin, and write to stdout. If you're wanting to do something like this in Unix:

cat somefile | yourprogram | someotherprogram | etc

yourprogram would simply read from stdin, which is the stdout of cat, and someotherprogram would read from stdin, which is the stdout of yourprogram. Remember, stdin and stdout are no different than any other FILE reference, so you can use the same routines to read from these streams as you do others. e.g.: fgets(), fread(), fwrite(), etc..

char buffer[250] = { 0 };
fgets(buffer, 250, stdin);

If this was in "yourprogram", this would read the first 250 bytes from the stdout of cat, which in this case would be the first 250 bytes of somefile. Hope this points you in the direct direction.
 

mosdef

Banned
May 14, 2000
2,253
0
0
I don't want to change my program at all though. I am only using cin's and cout's. I think I made this more complex than it should be. This is for a class, and we are supposed to use g++ for Unix, which is great but not convenient like an IDE.

No code should be changed to solve this, I simply want input to be direct in from a file and out to a file. I still want the standard input, but this should come from a file that is in a sense "automatically typed" into the program rather than manually typed by a user. Then any output sent to the standard output (screen) should be directed to a file which makes it easier for me to view and manipulate.

-mosdef
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0


<< I still want the standard input, but this should come from a file that is in a sense "automatically typed" into the program rather than manually typed by a user. Then any output sent to the standard output (screen) should be directed to a file which makes it easier for me to view and manipulate. >>



Ok then, assuming your program is correct:

cat somefile | yourprogram > youroutputfile

That's it.