![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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; } |
|||
| Google The UNIX and Linux Forums |