new char vs new char[size]
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.
Code:
char *buf = new char[256];
this means allocating 256 element.
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:
Code:
#include <iostream>
using namespace std;
int main()
{
char *buf2 = new char;
strcpy(buf2, "hellooooooooooooooooooooooo!");
cout << buf2 <<"\n";
delete buf2;
return 0;
}
Do i see it right or am i missing the point?
I see all the time this.