Please don't top-post. Put your reply below (or in line with when
applicable) the message you are replying to. That makes it easier to
follow the thread.
Hi there!!!!!!!!!1111
I am sending my program.
Just please let me know how can i write different data to different
files.
I haven't analysed your code in detail as it's not a very minimal
example, but ...
# include<iostream.h>
# include<string.h>
# include<fstream.h>
It's not directly related to your question, but C++ does not have
headers called <iostream.h> or <fstream.h>
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.4
You want <iostream> and <fstream> for the standard library. Note that
both those put all the names you are using (cout, ofstream etc. inside
the std namespace).
There is a header <string.h> for the C library string-as-array-of-char
functions. There is also <string> which is the C++ library string
class, a completely different thing. I don't know which you want. I may
be missing something scanning your code, but you don't appear to be
using anything from either, so no need for the include. If you do need
one, prefer <string> and use std::string from the C++ standard library.
void sequence::get_line_from_file()
This seems like a very bad choice of name. The function's job appears
to be to read and process the entire file line by line. The name
suggests it reads just one line, and suggests nothing about any
processing at all. Something like sequence:
rocess_from_file might be
better.
{
ifstream fin;
fin.open(filename,ios::in);
ofstream fout;
fout.open("output.txt",ios:
ut);
Here you have created an object of type ofstream called fout. If you
create another one called another_fout, initialised with a different
filename, e.g. "another_output.txt", you can use fout for the things
you want to write to output.txt and another_fout for the things you
want to write toanother_output.txt. Also, there is no need to construct
and open the objects as separate steps. And ios::in and ios:
ut are
assumed for ifstream and ofstream so you don't need to specify them.
ifstream fin(filename);
ofstream fout("output.txt");
That's not the way eof works.
http://www.parashift.com/c++-faq-lite/input-output.html
You need to check for eof *after* input fails.
<snip lots of code that outputs to cout and fout>
You seem quite happy with send output to two different places, cout and
fout. Just create ofstream objects for all the files you want to output
to and send the appropriate output to the appropriate ofstream.
<snip>
Gavin Deane