Making proper wrappers.

This is a discussion on Making proper wrappers. within the C++ Programming forums, part of the General Programming Boards category; Hope this isn't a stupid question, but Im trying to make a proper wrapper for printf. I get the proper ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    69

    Making proper wrappers.

    Hope this isn't a stupid question, but Im trying to make a proper wrapper for printf.

    I get the proper output doing the following:
    Code:
    text.hprintf("test\n");
    The output is:
    Code:
    test
    But I get a wierd output if I do:
    Code:
    text.hprintf("test\n%i", 123456789);
    The output is:
    Code:
    test
    1244892
    Here's the small source.

    main.cpp
    Code:
    //Alot of these includes are not used.
    //Most will be used in the future.
    #include <cstdlib>
    #include <fstream>
    #include <iostream>
    #include <fstream>
    #include <windows.h>
    #include <cstring>
    #include <time.h>
    #include "output.h"
    
    CTextOutput text;
    
    int main(){
    	char omfg;
    	int i = 0;
    	while(1){
    		if(i==0)
    		text.hprintf("test\n%i", 123456789);
    		std::cin>>omfg;
    		i=1;
    		}
    	return 0;
    }
    output.h
    Code:
    #ifndef OUTPUT_H
    #define OUTPUT_H
    
    class CTextOutput
    	{
    
    	private:
    	
    	public:
    
    	int hprintf(const char* string, ...);
    	int haprintf(const char* string, ...);
    
    	};
    
    #endif
    output.cpp
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <windows.h>
    #include <string>
    #include <cstring>
    #include <time.h>
    #include "output.h"
    
    int CTextOutput::hprintf(const char* string, ...)
    {
    printf(string);
    return 0;
    }
    int CTextOutput::haprintf(const char* string, ...)
    {
    printf("<<: ");
    printf(string);
    return 0;
    }
    This was my attempt at a custom wrapper. Any ideas?
    Last edited by bladerunner627; 11-02-2005 at 03:00 PM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    1. my first question: why bother? use iostream class.

    2. baring that, you need to use functions and macros in STDARG.H to access the optional parameters. See MSDN for example program.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by bladerunner627
    Any ideas?
    http://www.eskimo.com/~scs/C-faq/q15.5.html
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Quote Originally Posted by Dave_Sinkula
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. thinking about making a network traffic monitor
    By jimjamjahaa in forum C++ Programming
    Replies: 9
    Last Post: 10-13-2005, 11:38 AM
  2. Making control...
    By Finchie_88 in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2004, 01:42 PM
  3. Making dll's in C???
    By frolicchap in forum C Programming
    Replies: 2
    Last Post: 02-03-2003, 04:15 AM
  4. How to find the proper divisor?
    By yusiye in forum C Programming
    Replies: 6
    Last Post: 07-24-2002, 01:14 PM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21