how to make this programm with class????

K

Kostadis.Spirou

how can i make this programm with class????

#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;

int main()
{
char temp_char [200];
string file1,file2;
int i=0;

ifstream indata;

indata.open("config.txt");
if(!indata)
{
cerr << "Error: file could not be opened" << endl;
exit(1);
}

int first_row=true;
while (!indata.eof())
{
while (indata.getline(temp_char,200,'\n'))
{
if (first_row)
{
file1=temp_char;
first_row=false;
//cout<<file1<<endl;
}
else
file2=temp_char;
//cout<<file2<<endl;
}
}
indata.close();
char * buffer;
int long size;
buffer = new char [size];//allocate memory for file content

ifstream examplefile (file1.data());
ofstream fout (file2.data());
if (! examplefile.is_open())
{ cout << "this thing doesn't work "; exit (1); }

while (! examplefile.eof() )
{
examplefile.getline (buffer,size);//get line tou *.txt file
i+=1;
fout << buffer << endl;
}
examplefile.close();
fout <<"\n\nthe lines of this *.txt are: \t"<<i<<endl;
fout.close();
cout <<"\nthe procedure has been done"<<endl;
return 0;

}
 
M

mlimber

ben said:
What do you mean?

The OP asked, "how can i make this programm with class?" by which I
assume he means, How can I write this program with style and panache?
You know, really classy code!

My first suggestion would be to indent the source code (n.b., one line
of the OP's code *is* indented, making me think this is the OP's habit,
not a cut-n-paste problem), and my second suggestion would be to
consult our previous comments on what is essentially the same code:

http://groups.google.com/group/comp.lang.c++/browse_frm/thread/798fb428c516f654

If the OP meant, how can I incorporate this code in a class, well, that
depends on how it will be used, but a good C++ book would be of help.
Such a book is _Accelerated C++_ by Koenig and Moo.

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top