My problem reqs a simulation code ( *.exe), which shd read the inputs from a file ( *.in) and after calculations , write the results to an output file ( *.out) .The names of the input and output files are hardcoded.

I shd be able to execute my sim code in batch mode and generate the output file. All this in C++.

Cld u please help me?


10 Years
Discussion Span
Last Post by Arvinth

You will probably get more help if you are more specific in what your question is and show effort of having worked on the problem yourself.


I do not have problems with coding or the algo.
What I have to do is integrate the .exe with another software (isight), and this .exe shd read from a .in and generate a .out. I shd also be able to run this in batch mode.

For instance,
I have 2 inputs ... length and width in .in file

The .exe calculates the area and generates the output to a .out file

I'll have to integrate all three to isight and run an optimisation process, which I can manage on my own

I need help with the way to go abt reading from a .in file in a .c sim code and generate output to a .out file.

Just the procedure will be of great help or any links if possible.

Donno if I am in the right place

Tell me what kinda code you'll require... file handling is one way I cannot go abt doing this. Figured that much.

Thanks neways


>>file handling is one way I cannot go abt doing this

The only other way I know of is to redirect the input and output on the command line.

c:> myprogram < infile.in > outfile.out

That will redirect the file's contents to stdin just as if you typed the information on the keyboard, and redirect stdout to a file instead of displaying it on a console screen.

But I don't know why you can't just use FILE and associated C file handline functions to read the input file and write the output file.


shd? abt? What do these acronyms stand for???

"shd" is should

"abt" is about


Thanks a bunch.

What I mean by running in batch mode...
At the prompt, if my file name is test.exe , on typing the file name, the output file should be generated.
Now, test.exe is created after I run my test.c file.

Is file handline fns the only way to do this?


Here is a code:

void main()
    char ch1[50]="The length is : ";char ch2[50]="The width is : ";
    float l=8.0; float w=6.0;float a,p;
    char ch3[50]="The area is : ";char ch4[50]="The perimeter is : ";
    float temp1,temp2;

    ofstream outfile("newone.in");

    ifstream infile("newone.in");
    ofstream outf("newone.out");



What will a .exe of this do every time I run it?

In another software, I am giving it permission to replace the values of l and w in my input file with its own randomly generated values, calculate new area and perimeter, and write it in the output file... this runs in a loop until I optimise my area. Now, after it replaces the values in the input file, it uses the .exe to do the new calculations and carry on for every run.

When, it runs the .exe, does it re-initialise the values of l and w?
What does running the .exe do?

Edited by pyTony: fixed formating

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.