is use of pointer variable right?
hi i have the follwing problem.
i have one function openWriteStream ()
now this function is having protype like
this function opens a file and return the pointer of type ofstream
now i want to open a file andwrite somting to that file so i am trying somthing like this tell me if this is correct?
out = openWriteStream ()
*out <<"i want to write this to file";
is it right?and is this piece of code will help in writing to thefile opened by openwritestream?
this is terrible, really, but yes it will work provided your function allocated the pointer inside it (var = new ofstream)
what is wrong with
out << "text";
1) gets rid of potential pointer errors
2) uses debugged, language availble code
3) is faster
4) is easier to read, and easier to write
I odn't see the point in calling a function that does what the fstream class's constructor already does: open the stream. However, if you must use such a function, at least pass the stream object by reference to the function:
int OpenStream (fstream & str);
Then check the return status to see whether the operation succeeded. Again, this is pretty redundant because you don't need to reinvent the wheel here: simply write:
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL