I found one article which is not in English but there are some parts in the code which are very confusing. The code was not explained too much good but I see no sense of
I commented the cin.get thing, because I see non-sense to use it here.
I see no point of it. Do you have idea why author sets the actual position of pointer to the end of file/buffer and then tries to add data? It is logical that it will not be possible to add data, dont you think? The if block will never be true. Non sense example huh?
What is wrong with this code? I would like to change it to work like this:
I would like to append data on the begin of the buffer and then, if the string is too long, so it will print error, but if it is not too long, so it will print success.
You are exactly right -- the buffer is too small. The problem is that the old strstream class has no idea that it is too small -- it believes you when you tell it that the buffer is bigger than it is.
Since you are using Microsoft's compiler, there is actually no need for you to use the old strstream classes. Use the modern stringstream instead. Then you never need to worry that the buffer is too small.
I am not sure what the original code should do. I think it should illustrate the limit of the buffer. So if you get "hello" in char[10] you are OK, but if you try "Hello World" so you fail because you are out of the limit.