Answer

问题及解答

使用 c++ 打印向量

Posted by haifeng on 2017-06-21 08:49:05 last update 2017-06-21 08:49:05 | Edit | Answers (2)

使用 c++ 打印向量

1

Posted by haifeng on 2017-06-21 08:55:01

/**
 * 输出向量的函数
 */
template <typename Comparable>
void printVector(vector<Comparable> & v)
{
    for(unsigned int i=0 ; i < v.size() ;i++)
    {
        cout << v[i] << " " ;
    }
	cout << endl;
}

2

Posted by haifeng on 2017-06-21 08:53:27

template <typename Comparable>
void printv( vector<Comparable>& a )
{
    vector<int>::iterator itr;
    for( itr = a.begin( ); itr != a.end( ); itr++ )
        cout << *itr << " ";
    cout << endl;
}