I think all of your problems stem from re-opening the file in your functions. Opening a file stream in write mode will truncate the file to zero length, so every time you call print(), the data in the file gets wiped out.
One way to fix it without significant changes is open the file in main() just before your second loop, remove the call to open() in print(), and finally remove the call to close() in display():
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>
using namespace std;
int array[7][4];
fstream file2;
template< typename T > void display( const vector< vector<T> >& matrix )
{
for(int i = 0; i < 7; ++i)
{
for(int j = 0; j < 4; ++j)
{
array[i][j] = matrix[i][j];
file2 << array[i][j] << " ";
}
file2 << "\n";
}
file2 << "\n";
}
template< typename T >
vector< vector<T> > get( const vector< vector<T> >& m, size_t n, size_t i, size_t j )
{
const size_t N = m.size() ;
vector< vector<T> > slice(n) ;
for( size_t k = 0 ; k < n ; ++k )
for( size_t l = 0 ; l < n ; ++l )
slice[k].push_back( m.at(k+i).at(l+j) ) ;
return slice ;
}
template< typename T > void print( const vector< vector<T> >& m )
{
for( size_t i = 0 ; i < m.size() ; ++i )
{
for( size_t j = 0 ; j < m[i].size() ; ++j )
{
file2 << m[i][j] << " …