我有一个vector<set<char> >
数据结构(交易数据库),我想知道它的大小.当我使用sizeof()时,每个set<char>
大小为24,尽管该组包含3,4或5个字符.后来,当我使用sizeof()时,vector<set<char> >
大小为12 ...我想这不是了解数据结构大小的方法.有帮助吗?谢谢.
我正在尝试为返回流的二叉树实现一个方法.我想使用方法中返回的流来显示屏幕中的树或将树保存在文件中:
这两个方法都在二叉树的类中:
声明:
void streamIND(ostream&,const BinaryTree<T>*);
friend ostream& operator<<(ostream&,const BinaryTree<T>&);
template <class T>
ostream& operator<<(ostream& os,const BinaryTree<T>& tree) {
streamIND(os,tree.root);
return os;
}
template <class T>
void streamIND(ostream& os,Node<T> *nb) {
if (!nb) return;
if (nb->getLeft()) streamIND(nb->getLeft());
os << nb->getValue() << " ";
if (nb->getRight()) streamIND(nb->getRight());
}
Run Code Online (Sandbox Code Playgroud)
这个方法在UsingTree类中:
void UsingTree::saveToFile(char* file = "table") {
ofstream f;
f.open(file,ios::out);
f << tree;
f.close();
}
Run Code Online (Sandbox Code Playgroud)
所以我重载了BinaryTree类的运算符"<<"以使用:cout << tree和ofstream f << tree,但是我收到了下一条错误消息:对`operator <<的未定义引用(std :: basic_ostream>&,二叉树&)"
PS树存储Word对象(带有int的字符串).
我希望你能理解我的英语不好.谢谢!而且我想知道一个关于STL的初学者的好文本,它解释了所有必要的,因为我浪费了所有时间在这样的错误.
编辑:saveToFile()中的树被声明:BinaryTree <Word>树.