C++ : friend declaration ‘declares a non-template function

There are two different issues in your code, the first is that the friend declaration (as the warning clearly says, maybe not so clear to understand) declares a single non-templated function as a friend. That is, when you instantiate the template NVector<int,5> it declares a non-templated function std::ostream& operator<<(std::ostream&,NVector<int,5>) as a friend. Note that this … Read more

How do the stream manipulators work?

The standard defines the following operator<< overload in the basic_ostream class template: basic_ostream<charT,traits>& operator<<( basic_ostream<charT,traits>& (*pf) (basic_ostream<charT,traits>&) ); Effects: None. Does not behave as a formatted output function (as described in 27.6.2.5.1). Returns: pf(*this). The parameter is a pointer to a function taking and returning a reference to a std::ostream. This means that you can … Read more

Floating point format for std::ostream

std::cout << std::fixed << std::setw(11) << std::setprecision(6) << my_double; You need to add #include <iomanip> You need stream manipulators You may “fill” the empty places with whatever char you want. Like this: std::cout << std::fixed << std::setw(11) << std::setprecision(6) << std::setfill(‘0’) << my_double;