1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

#include <iostream>
#include <complex>
#include <array>
#include <sstream>
#include <iomanip>
template < std::size_t N, typename T = double >
using matrix_type = std::array< std::array< std::complex<T>, N >, N > ;
template < std::size_t N, typename T >
std::istream& get_matrix( std::istream& stm, matrix_type<N,T>& matrix )
{
for( auto& row : matrix )
for( auto& value : row ) stm >> value ;
if( stm.fail() ) matrix = {} ;
return stm ;
}
template < std::size_t N, typename T >
std::ostream& put_matrix( std::ostream& stm, const matrix_type<N,T>& matrix )
{
for( const auto& row : matrix )
{
for( const auto& value : row ) stm << value << ' ' ;
stm << '\n' ;
}
return stm ;
}
int main()
{
const std::size_t N = 3 ;
matrix_type<N> matrix ;
{
std::istringstream test_file( "(1,1) (2,0) (0,1)\n"
"(2,0) (0,0) (1,0)\n"
"(0,1)(1,0) (2,0)\n" ) ;
if( get_matrix( test_file, matrix ) )
std::cout << "matrix was read in successfully\n" ;
}
std::cout << std::fixed << std::setprecision(1) ;
put_matrix( std::cout, matrix ) ;
}
 