LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-28-2004, 09:36 PM   #1
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
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?
 
Old 06-28-2004, 09:43 PM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
Code:
#include <stdio.h>
...
       printf("%s", myString.c_str());
close enough?
 
Old 06-28-2004, 09:45 PM   #3
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Original Poster
Rep: Reputation: 32
I thought it was bad to do that.
 
Old 06-28-2004, 11:46 PM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Questions about custom C++ string class. lowpro2k3 Programming 1 08-23-2005 01:06 PM
is there a c++ binary safe string class? Thinking Programming 3 08-11-2005 07:18 PM
Send string to std output without interpreting (script) ta0kira Programming 6 06-29-2005 09:50 AM
Linking problem with string class live_dont_exist Programming 4 04-09-2005 09:07 AM
C++ std::string to int Slaxx Programming 1 10-30-2004 11:03 PM


All times are GMT -5. The time now is 04:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration