nomi_txt[cont] = n_cartelle[i];
Since you never set the size of nomi_txt
, this will result in undefined behavior as you will be accessing elements out of the bounds of the vector. If you want nomi_txt
to have the same number of elements as n_cartelle
, you need to resize it:
nomi_txt.resize(n_cartelle.size());
prior to the loop.
Barmar already mentioned the issue with closing the std::ofstream
prior to reopening the file for input.