G
gipsy boy
Silly problem, but it's going to teach me something cause I'm confused..
How do I store the letters of a char buf[12] into a string?
Whenever I do this, when buf exists the scope of its creation, the
string data is lost.
This is the current code :
char buf[12];
int l = strftime(buf,12,"%d/%m/%y",&birthDate);
for(int i=0;i<l;i++) birthDateStr = buf;
cout << birthDateStr << l << endl;
Now, this works, but when I exit the scope (birthDateStr is a class
member), birthDateStr is suddenly empty again! Why?
If you have a better way (perhaps with a temporary char * instead of a
heaped array), please explain it to me?
thanks,
How do I store the letters of a char buf[12] into a string?
Whenever I do this, when buf exists the scope of its creation, the
string data is lost.
This is the current code :
char buf[12];
int l = strftime(buf,12,"%d/%m/%y",&birthDate);
for(int i=0;i<l;i++) birthDateStr = buf;
cout << birthDateStr << l << endl;
Now, this works, but when I exit the scope (birthDateStr is a class
member), birthDateStr is suddenly empty again! Why?
If you have a better way (perhaps with a temporary char * instead of a
heaped array), please explain it to me?
thanks,