The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh scripting sprintf gfhgfnhhn Shell Programming and Scripting 2 07-05-2006 05:11 AM
sprintf function whatisthis High Level Programming 1 05-01-2006 01:58 PM
mcs equivalent in HP-UX vibhor_agarwali HP-UX 5 04-28-2005 07:43 AM
problem with sprintf snprintf in Solaris diganta SUN Solaris 7 12-24-2004 04:41 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-19-2008
Read Only
 

Join Date: Jun 2006
Posts: 105
equivalent of sprintf in C++

Hi
My requirement is to convert the following to C++

char buffer[90];
sprintf(buffer,"%s %-50s %6s %-6d %s\n",a.substr(0,5),a.substr(10,20))

Since the buffer is of varying length, i cannot hardcode the value as 90.
i would like to convert the buffer to string object so that it can receive any number of bytes. So ... i will be converting buffer to string object.

So i need some formatting in C++. Is there any thing similar to sprintf?

Regards
Dhana
Reply With Quote
Forum Sponsor
  #2  
Old 05-20-2008
Registered User
 

Join Date: Dec 2007
Location: Simi Valley, CA
Posts: 28
Arrow stringstream

Use sstream.

#include <sstream>
using namespace std;

int main()
{
stringstream ss;
ss<<"Formatted date example (H:M:S):"<<hour<<":"<<min<<":"<<sec<<endl;
cout<<ss.str().c_str();
return 0;
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0