I
I
igoodmood2016-09-10 16:52:31
C++ / C#
igoodmood, 2016-09-10 16:52:31

How to open/close a text file using class methods?

When studying classes, the question arose: how to implement the opening / closing of a text file using a class method?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slavka, 2016-09-10
@Slavka_online

what for ? And why just open it?

G
Guzh, 2016-09-10
@Guzh

void method()
{
ofstream fout("sample.txt");
fout << "Text text texT";
fout.close();
}
Here is the method to open/write/close. If you need to break these 3 actions into methods, then just create a global file variable and work with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question