如下面程序
vector< int > a;
a.push_back(1);
a.push_back(2);
a.push_back(3);
a.push_back(4); /* */在VC调试中运行到上面注释那行,在watch窗打入a,结果是
allocator
a.first
a.last
a.end只能看到第一个值如何才能看到所有值,谢谢
vector< int > a;
a.push_back(1);
a.push_back(2);
a.push_back(3);
a.push_back(4); /* */在VC调试中运行到上面注释那行,在watch窗打入a,结果是
allocator
a.first
a.last
a.end只能看到第一个值如何才能看到所有值,谢谢
不过可以写一个打印所有元素的小函数。代替调试
如果象要查看不同的数据类型,需要对data2str模板函数进行特化扩充,
下面的例子只支持inttemplate <class type>
string data2str(type value)
{
int i;
100 = i;
}template <>
string data2str(int value)
{
string ret;
char buf[100];
memset(buf,0,100);
itoa(value,buf,10);
ret = buf;
return ret;
}template <class dtype, template <class _t> class contain>
class ext_contain : public contain<dtype>
{
public:
typedef typename contain<dtype>::iterator iterator;
string ToStr() {
string ret;
iterator lp;
for (lp = begin(); lp != end(); lp++) {
ret += data2str(*lp);
ret += " ";
}
return ret;
}
}; void test()
{
int i;
string info;
ext_contain<int,vector> lv;
for (i = 0; i < 100; i++) {
lv.push_back(i);
}
info = lv.ToStr();
cout << info.c_str() << endl;
ext_contain<int,list> ll;
for (i = 100; i < 150; i++) {
ll.push_back(i);
}
info = ll.ToStr();
cout << info.c_str() << endl;
}