Re: in c++ I need a pointer to a pointer ?????
I can build a linked list with no problems.
Me too, it's easy:
std::list<long double> fou;
Why is Root_node public? Why are all other members public, too? Why don't
you initialise any members but Root_node. Why aren't the others called
Child_node and Sibling_node? Also, is the Root_node the root of the tree or
is it the parent node? Do you intend objects of this type to be copyable
and assignable, are you satisfied with the compiler-generated defaults?
Lastly, which of the pointers signify ownership of the pointee and which
tree* tree::add_node(tree *root)
found = lineinput.find("</");
tree *node = *root;
root->data = lineinput;
if (found >0)
if (found <=0)
try as I might this worked but didn't.
Some comments (in particular on tree::add_node):
- std::string::find returns a std::string::size_type. If the requested
substring was not found, the value is std::string::npos. Assigning to an
int and comparing to zero is wrong.
- iostream::eof() returns true _*after*_ an input operation failed due to
reaching the end of the file.
- What is the meaning of the input value, what the meaning of the
- Why does your function not return anything (i.e. just invoke 'return;',
without a value)?
- There is a pointer called 'node' which is unused.
- The function say it adds a node, but where is that node?
- ifstreams (note the leading 'i') are always opened for input.
- array 'str' is unused.
- string 'lineinput' is never filled but only read.
- When I see a pointer, I assume that NULL is a valid value to pass. If you
don't mean that, either use assert() and document that or use a reference
instead of a pointer.
Then I was told oh this wont work unless you use a pointer to a
pointer...something like **root.
When someone suggests fixing one thing by using a pointer to a pointer,
please ask that person to clarify what they meant. AFAICT, there is no need
to use a pointer to a pointer in order to build a tree.
Another problem is also that it's hard to guess what you want because you
didn't comment anything except calling an 'ifstream' an 'input file', which
is useless because it is obvious.
can someone tell me what a pointer to a pointer does and if there is
something I can find to explain the syntax behind it?
A pointer to a pointer is just another type of pointer, only that the object
it points to is also a pointer and not a class or a builtin type. Check out
the reviews section at accu.org for good books on learning C++.
Other than that, take one step back. You are mixing up too many things that
now seem to have gotten over your head. Either write a parser for XML or
write a type that holds a tree-like structure. Only when those two tasks
are finished, you can start to combine them into one program that builds a
tree from an XML file.