this is a programm that opens config.txt and reads the 2 lines that are
inside it,after that it copies them and i want to put them as
parametres at
ifstream examplefile (file1.data());
ofstream fout (file2.data());
but when i try to run it it doesn't work at all.
any suggestions what to change in my code?
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
using std::ifstream;
int main()
{
char *word;
char temp_char [200];
string file1,file2;
int long size1;
word = new char [size1];
int i=0;
char * buffer;
long size;
ifstream indata;
int num;
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();
size=1000;
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.close();
cout <<"the lines of this *.txt are: "<<i<<endl;
}