473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

filebuf object Vc++

sangeetha jagannathan
hi
can anyone explain me this code, instruction by instruction. i am not able to follow it.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <fstream.h>
  3. #include <stdio.h>
  4. #include "logger.h"
  5. #include "dostuff.h"
  6.  
  7. class MyOStream : public ostream {
  8.   public:
  9.     MyOStream() : ostream() {
  10.       filebuf * buf = new filebuf();
  11.       int i = 0;
  12.       char buffer[256] = "log000000.txt";
  13.       while (!buf->open(buffer, ios::out | ios::noreplace)) {
  14.         sprintf(buffer, "log%06d.txt", ++i);
  15.       }
  16.  
  17.       ios::init(buf);
  18.       ios::delbuf(1);
  19.     }
  20. };
  21.  
  22. int main(int, char **) {
  23.   MyOStream os;
  24.   if (os.good()) {
  25.     Logger log(os);
  26.     do_stuff(log);
  27.   }
  28.  
  29.   return 0;
  30. }
Feb 14 '07 #1
3 2329
sicarie
4,677 Expert Mod 4TB
hi
can anyone explain me this code, instruction by instruction. i am not able to follow it.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <fstream.h>
  3. #include <stdio.h>
  4. #include "logger.h"
  5. #include "dostuff.h"
  6.  
  7. class MyOStream : public ostream {
  8.   public:
  9.     MyOStream() : ostream() {
  10.       filebuf * buf = new filebuf();
  11.       int i = 0;
  12.       char buffer[256] = "log000000.txt";
  13.       while (!buf->open(buffer, ios::out | ios::noreplace)) {
  14.         sprintf(buffer, "log%06d.txt", ++i);
  15.       }
  16.  
  17.       ios::init(buf);
  18.       ios::delbuf(1);
  19.     }
  20. };
  21.  
  22. int main(int, char **) {
  23.   MyOStream os;
  24.   if (os.good()) {
  25.     Logger log(os);
  26.     do_stuff(log);
  27.   }
  28.  
  29.   return 0;
  30. }
What parts do you not understand? When you start reading it, where do you get stuck?
Feb 14 '07 #2
What parts do you not understand? When you start reading it, where do you get stuck?
i get stuck here

filebuf * buf = new filebuf();
int i = 0;
char buffer[256] = &quot;log000000.txt&quot;;
while (!buf->open(buffer, ios::out | ios::noreplace)) {
sprintf(buffer, &quot;log%06d.txt&quot;, ++i);
}
Feb 15 '07 #3
enri
10
i get stuck here

filebuf * buf = new filebuf();
int i = 0;
char buffer[256] = "log000000.txt";
while (!buf->open(buffer, ios::out | ios::noreplace)) {
sprintf(buffer, "log%06d.txt", ++i);
}
The first line creates a new object filebuf by mean of its constructor "filebuf()", and address it using a pointer to filebuf called "buf".
Then a file name "log000000.txt" is initialized.
The cyvle, checks if a file named "log000000.txt" exist, using the filebuf method open(). If it exist, it changes the file name to "log000001.txt", and checks it existence, and son on incrementing the file number to log000002.txt, log000003.txt and so on
Feb 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Maya | last post by:
Apart from being a pointer, what would be the benefit of using 'std::filebuf' than using the std::fstream? As far as I can see, I would use the same methods in 'filebuf' that I would when using...
2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
2
by: Manfred Eckschlager | last post by:
Hi, In Linux C++ there was an easy way to build a stream form a socket like: int sockFd = socket(AF_INET,SOCK_STREAM,0); filebuf *netBuf = new filebuf( sockFd ); -and then iostream...
4
by: Peter Hemmingsen | last post by:
Hi, I have a dotnet object (implemented in mc++ and used in c#) which have a property called "Info". The Info property is also a dotnet object (implemented in mc++). In the constructor of the...
2
by: Craig | last post by:
I've been writing C# code for maybe as much as 2 weeks now. The code I'm writing is exposed as a garden variety COM object that VC++ 6.0 and VB 6.0 can use. Coincidentally my COM development...
2
by: Olaf Baeyens | last post by:
Another question: I have a mixed managed/unmanaged MVC++ 2003 project and it uses a VC++ 6.0 lib file that only uses windows functionality no MFC. So far it worked fine. But somehow now I get...
1
by: nitroamos | last post by:
i'm working on improving the IO for the software project i'm working on to do two extra things. first, i'm going to add HDF5 functionality, and second, add the ability to write binary output. the...
0
by: Jim Owen | last post by:
Hi, I have a COM object that I'm trying to use from within a VC++ dll. I'm pretty sure that the COM object was written in VB although we didn't write it. I registered the dll and have been able...
1
by: SpreadTooThin | last post by:
I am simply trying to see if I am at the end of a file... In my class I maintain a filebuf. In my class I want to provide a method to see if i am at the eof... My question is can I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.