The code below tries to create 800 files in the ./out folder. On Linux Debian with g++ 4.9.2 the program works correctly. But on Windows 7 or 8 with g++ 5.2.0 (MinGW) the program stops at 509 files. The error seems to be a combination of using emplace_back and ofstream in a constructor of class Task. Is it bug?
//g++ -std=c++11 main.cpp
#include <sstream>
#include <fstream>
#include <list>
#include <iostream>
#ifdef _WIN32
#include <io.h>
#else
#include <sys/stat.h>
#endif
using namespace std;
int i;
struct Task
{
ofstream out;
Task(string file_name): out(file_name)
{
if(!out) {cout<<i<<"\n"; exit(1);}
}
};
int main()
{
#ifdef _WIN32
string output_folder = ".\\out";
mkdir(output_folder.c_str());
output_folder+="\\";
#else
string output_folder = "./out";
mkdir(output_folder.c_str(),S_IRWXU);
output_folder+="/";
#endif
list<Task> ltask;
for(i=0; i<800; i++)
{
ostringstream os;
os<<output_folder<<i;
ltask.emplace_back(os.str());
}
return 0;
}