| | |
C++ prog
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Solved Threads: 0
Hi
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?
Thanks
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?
Thanks
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Solved Threads: 0
Alright,
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
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.
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.
The only other way I know of is to redirect the input and output on the command line.
C++ Syntax (Toggle Plain Text)
c:> myprogram < infile.in > outfile.out
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.
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Solved Threads: 0
Here is a code:
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
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");
outfile<<ch1<<l<<endl<<ch2<<w;
outfile.close();
ifstream infile("newone.in");
ofstream outf("newone.out");
infile.getline(ch1,50);
infile>>l;temp1=l;
infile.getline(ch2,50);
infile>>w;temp2=w;
a=l*w;
p=2*(l+w);
outf<<ch3<<a<<endl;
outf<<ch4<<p<<endl;
infile.close();outf.close();
}
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.
Doubts:
When, it runs the .exe, does it re-initialise the values of l and w?
What does running the .exe do?
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
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");
outfile<<ch1<<l<<endl<<ch2<<w;
outfile.close();
ifstream infile("newone.in");
ofstream outf("newone.out");
infile.getline(ch1,50);
infile>>l;temp1=l;
infile.getline(ch2,50);
infile>>w;temp2=w;
a=l*w;
p=2*(l+w);
outf<<ch3<<a<<endl;
outf<<ch4<<p<<endl;
infile.close();outf.close();
}
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.
Doubts:
When, it runs the .exe, does it re-initialise the values of l and w?
What does running the .exe do?
![]() |
Similar Threads
- Prog and Logic Question for beginner (Legacy and Other Languages)
- help me in my password checking prog (C++)
- plz debug my prog to insert value in an array (C++)
- how to run simple c++ prog from another system? (C++)
- help with this prog (C++)
- Prog to list ASCII codes (beginners' stuff) (C)
Other Threads in the C++ Forum
- Previous Thread: Turbo C help
- Next Thread: Building DLL from .LIB & .H
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






