Not to bother anyone, but i have ran into an issue with a class of mine, somehow when i write to a file with the FILE*
and fprintf()
function i don't get any text in my text file that i created, i have searched all over youtube and i don't know what i'm doing wrong, because my code is the same.
Heres a copy of my .c++ and .h code:
main.c++:
#include <iostream>
#include "../include/include.h"
using namespace std;
int main() {
write_file wf("test.txt");
wf.write_line("Hello, world!");
return 0;
}
include.h:
#ifndef INCLUDE_H
#define INCLUDE_H
#include <iostream>
class write_file {
public:
write_file(const char *file_name) {
FILE* fp = fopen(file_name, "w");
}
void write_line(const char *line) {
fprintf(fp, "%s\n", line);
}
void close() {
fclose(fp);
}
private: FILE* fp;
};
#endif /* include.h */