what does this block of code do?

Nov 18, 2018 at 6:20pm
Can someone explain me, line by line what does this code do?
Thank you!
code:

using namespace std;



void LOG(string input) {
fstream LogFile;
LogFile.open("dat.txt", fstream::app);
if (LogFile.is_open()) {
LogFile << input;
LogFile.close();
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13

using namespace std;



void LOG(string input) {
	fstream LogFile;
	LogFile.open("dat.txt", fstream::app);
	if (LogFile.is_open()) {
		LogFile << input;
		LogFile.close();
	}
}
Last edited on Nov 18, 2018 at 6:20pm
Nov 18, 2018 at 6:29pm
This is a function. The function is named "LOG". The function accepts a single input parameter, of type string, named "input".

The function creates an fstream object, named "LogFile". That fstream object is then opened; the file created is named "dat.txt". It is opened in such a way that if it already exists, new data will be added to the end of it.

If that file was opened successfully, the value of the input string is added to the function, and the file is closed.

In summary, this function adds a string to the end of a file named "dat.txt"
Nov 18, 2018 at 9:24pm
Thank you very much!
Topic archived. No new replies allowed.