!read.eof()
only checks for end of file, not errors reading the file, such as a networked mounted file system not being ready, disk error, or lack of permission to read the file. You should check for all failures, with while(read)
which has an overloaded operator to check everything for you. So, if the file fails, you stop trying to read from it. You should also check the status before trying to read from the file. As such, while(read) { ... }
is preferable to the do/while loop. After the loop, you might issue a warning or error to the user of you did not reach the end of file !read.eof()
so they can investigate that specific file.
Try to avoid char *
and char []
as much possible as this is highly error prone. You have a char[100]. What happens if the string is longer than 100 characters? read >> token
may overwrite the stack -- such as to damage the ifstream read
.
Consider using std::list<sub_node>
to avoid having to re-invent and re-debug the wheel? You would no longer need the next pointer as std::list already does that for you. This would leave far less code to debug.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…