I think people mix up this: char *buf = new char;
with this: char *buf = new char[256];
They mix up number of elements with number of bytes.
this means allocating 256 element.Code:char *buf = new char[256];
file.append(buf); and here you are using only one element of 256 and you can assign as many byte as you like to it.
Whereas here i can assign as many characters as i want with only one element,
this code's working:
Do i see it right or am i missing the point?Code:#include <iostream> using namespace std; int main() { char *buf2 = new char; strcpy(buf2, "hellooooooooooooooooooooooo!"); cout << buf2 <<"\n"; delete buf2; return 0; }
I see all the time this.