El ejemplo se enfoca en crear un archivo de texto con los datos que estan definidos en el objeto persona.
- fstream: Input/output stream class to operate on files.
// Create and open a text file
ofstream myFile(fileName, ios_base::app);
member constant | opening mode |
---|---|
app | (append) Set the stream's position indicator to the end of the stream before each output operation. |
ate | (at end) Set the stream's position indicator to the end of the stream on opening. |
binary | (binary) Consider stream as binary rather than text. |
in | (input) Allow input operations on the stream. |
out | (output) Allow output operations on the stream. |
trunc | (truncate) Any current content is discarded, assuming a length of zero on opening. |
// Use a while loop together with the getline() function to readByLine the file line by line
while (getline (myReadFile, myTextLine)) {
// Output the text from the file
myText = myText + myTextLine + "\n\r";
}
content.assign((istreambuf_iterator<char>(myReadFile)),
(istreambuf_iterator<char>()));