I am trying to write a program that will take a character array and write it to the next line in the file. I figured out the first line but how do i keep writing to that file on multiple lines?
1 2 3 4 5 6 7 8 9 10 11 12 13
char char_array[line.size()];
int k = 0;
for( int p = line.size()-1 ; p>=0 ; p-- )
{
char_array[k]=line[p];
k++;
}
ofstream out_file;
out_file.open("output.txt");
out_file << char_array << endl;
out_file.close();
cout<<char_array<<endl;
myfile << "this is the first line\nand this is the second one!";
//or
myfile << "third line" << endl;
myfile << "and the no 4!";
Also, you shouldn't do what you do on line 2.
Arrays have to be declared with const size. char* char_array = newchar[line.size()]; would be the right way.