You may be using ofstream which is an output stream class that operates on files.
EDIT: Remember to be passing the opening mode and the complete directory of the file you want to handle if it is not in the same folder as your program’s executable.
Example: f_out.open("C:\\Users\\Pasta\\teste.txt", std::ios::app);
See also the reference C++ Reference
std::ofstream Hypnos_FILE;
std::string TEXTO = "Escrevendo em arquivo de texto";
Hypnos_FILE.open("DATABASE\\Arquivo.txt", std::ios::app);
if (Hypnos_FILE.is_open())
{
std::cout << "Arquivo de texto aberto com sucesso!" << std::endl;
Hypnos_FILE << TEXTO;
}
else
std::cout << "Erro ao abrir arquivo de texto.";
Hypnos_FILE.close();
open (filename, mode);
Ios:in = Open for entry operations.
Ios:out = Open for exit operations.
Ios:: = Open in binary mode.
Ios:: = Set the starting position at the end of the file.
If this flag is not set, the starting position is the beginning of the file.
Ios: = All output operations are performed at the end of the file by adding the contents to the current file content.
Ios::trunc = If the file is opened for output operations and it already existed, its previous content is deleted and replaced by a new one.
Try to put the full file path. Could you provide more details? Which compiler are you using? Which operating system?
– Avelino
No. Only the file is not created, so I revised the code is correct.
– Diogo
Mac OS, @Avelino.
– Diogo