LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   std string class and printf (https://www.linuxquestions.org/questions/programming-9/std-string-class-and-printf-198889/)

The_Nerd 06-28-2004 08:36 PM

std string class and printf
 
This doesn't work:

Code:

#include <string>
unsing namespace std;

class MyStringType : public string
{
    public:
        void printf(char *, ...);
};

void MyStringType::printf(char *FormatString, ...)
{
    //etc ...
}

int main(int argc, char **argv)
{
    MyStringType;
    char *TestStr="Hello World!";
    MyStringType.printf("%s", TestStr);
}

This doesn't work. How can I make a wrapper for the standard C++ string class that adds a printf function?

aluser 06-28-2004 08:43 PM

Code:

#include <stdio.h>
...
      printf("%s", myString.c_str());

close enough?

The_Nerd 06-28-2004 08:45 PM

I thought it was bad to do that.

aluser 06-28-2004 10:46 PM

Well, it's not very c++ish and it will truncate if there's a \0 in the string. That's all that's wrong with it afaik


All times are GMT -5. The time now is 09:17 PM.