Now I like the way C++ handles strings; I find parsing so much easier in every way.
But...
Here's the way I handle strings and such, a few code examples. I was just wondering if there's a more efficient way, or if I'm doing some n00b error type things.
A pretty useless example i know, but anyway...Code:#include <iostream>
using namespace std;
int main ()
{
char* buffer = new char[120];
cout << "Enter a sentance: ";
cin >> buffer;
delete [] buffer;
return 0;
}
And another.Code:#include <iostream>
using namespace std;
char* ret_buffer ()
{
char* buf = new char[50];
return buf;
}
int main ()
{
char* buffer = new char[50];
strcpy (buffer, ret_buffer(), 50);
delete [] buffer;
return 0;
}
I was just wondering if there are any glaring mistakes? I just feel like I'm doing something wrong but can't put my finger on it. I have quarms about my second example where the function 'ret_buffer()' returns the pointer to a buffer (buf) which is never delete []'d.
Any help appreciated ;).
PS Please don't point out syntax errors I'll notice them after i've posted this and won't really care - we all know what it's supposed to do.