I want to create a list of empty files from a list of paths:
#include <fstream>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> paths{ "foo.txt", "bar.txt", "baz.txt" };
for (auto & path : paths)
{
std::ofstream new_file{ path, std::ofstream::trunc };
}
}
This works, but the release of my code is compiled with the highest level of optimization. So my question is: is it a guarantee that my files will be created? I am afraid that some compilers “see” that this variable is unused and do not consider this line, although the constructor has a desired side effect.