Klocwork throws
resource acquired to 'ofs.open("file.txt", std::ofstream::out)' may be lost here
for the below piece of code.
#include <iostream>
#include <fstream>
void main()
{
std::ofstream ofs;
ofs.open("file.txt", std::ofstream::out);
if (ofs.is_open())
{
std::cout << "file open success\n";
}
ofs.close();
}
I dont find any issues with the above code. Can someone explain what need to be done here to fix the issue.