This file read in some data from AD.txt, stores it to a string, and the writes the string to ADsubjects.txt. My write function seems to work fine but my read is not being called. Its not even going inside the read function to print the cout
statements. I assumed that if I just simply place the call function it should appear automatically. Here is my code:
#include <iostream>
#include<fstream>
#include <string.h>
#include<iomanip>
#include <cstdlib>
#define rmax 15
using namespace std;
string data1;
Read function:
void readSubjects(){
cout<<"inside read"<<endl;
ifstream is;
is.open("AD.txt"); //opening the file
cout<<"open text"<<endl;
while(!is.eof()){
char line[rmax];
cout<<line<<endl;
data1 += "\"";
is.getline(line,rmax);
for(int i=0; i<11;i++){
data1 += line[i];
}
data1 += "\" \\ ";
}
is.close();
}
Write function:
void writeSubjects(){
ofstream os;
os.open("ADsubjects.txt",ios::out);
os<<data1;
os.close()
}
Main function:
int main() {
readSubjects();
cout<<"read"<<endl;
writeSubjects();
cout<<"written"<<endl;
cout << "Hello, World!" << endl;
return 0;
}