- skipping spaces in a sprintf format - 6 Updates
- Is Copy-and-swap idiom too slow in assignment operator? - 1 Update
| Manfred <noname@add.invalid>: Oct 29 01:45AM +0200 On 10/29/2022 12:47 AM, Bart wrote: > printf("<%*s>\n",10,""); > "*" is used for a variable field width, padded on the left. "%-*s" will > pad on the right. Simpler, and probably closer to what the OP needs: sprintf (termin1.outbuffer, "%32s%8d", "PAGE:", prglab1.current_page); outwri (termin1.outbuffer); |
| Bart <bc@freeuk.com>: Oct 29 11:08AM +0100 On 29/10/2022 00:45, Manfred wrote: > Simpler, and probably closer to what the OP needs: > sprintf (termin1.outbuffer, "%32s%8d", "PAGE:", prglab1.current_page); > outwri (termin1.outbuffer); I thought I'd missed the obvious solution.. |
| Lynn McGuire <lynnmcguire5@gmail.com>: Oct 29 02:02PM -0500 On 10/28/2022 6:45 PM, Manfred wrote: > Simpler, and probably closer to what the OP needs: > sprintf (termin1.outbuffer, "%32s%8d", "PAGE:", prglab1.current_page); > outwri (termin1.outbuffer); Thank you both ! Lynn |
| Lynn McGuire <lynnmcguire5@gmail.com>: Oct 29 03:55PM -0500 On 10/28/2022 6:45 PM, Manfred wrote: > Simpler, and probably closer to what the OP needs: > sprintf (termin1.outbuffer, "%32s%8d", "PAGE:", prglab1.current_page); > outwri (termin1.outbuffer); Or, sprintf (termin1.outbuffer, "%66sPAGE:%8d", " ", prglab1.current_page); outwri (termin1.outbuffer); Thanks ! Lynn |
| Michael S <already5chosen@yahoo.com>: Oct 29 02:03PM -0700 On Saturday, October 29, 2022 at 10:02:55 PM UTC+3, Lynn McGuire wrote: > > outwri (termin1.outbuffer); > Thank you both ! > Lynn Consider bookmarking this page: https://en.cppreference.com/w/cpp/io/c/fprintf Also, if were are already discussing C-style formatted output in C++ group, I'd ask about opinion of members of comp/lang.c++ about boost::format(). I never used it myself, but the idea of combination of std::sstream class, which I consider the only good part of otherwise awful C++ "native" I/O classes with such obviously well-designed thing as printf-style formatting looks to me as very promising. C++20 has something similar (std::format), but for my personal taste it is too new and unproven. And different from C tradition for no obvious benefit. |
| Mike Terry <news.dead.person.stones@darjeeling.plus.com>: Oct 29 10:29PM +0100 On 29/10/2022 21:55, Lynn McGuire wrote: > Or, > sprintf (termin1.outbuffer, "%66sPAGE:%8d", " ", prglab1.current_page); > outwri (termin1.outbuffer); I'd suggest a minor improvement: ..."%66sPage:%8d", "",... Looking at: printf ("==%0s==\n", " "); printf ("==%0s==\n", ""); We get output == == ==== So I could say the empty string works more universally, and SAVES A BYTE OF DISK SPACE!!! :) Well, probably you would never want to skip 0 spaces, but hey... (it can't be bad to handle edge cases, even if you're convinced you'll never use them.) Mike. |
| "Öö Tiib" <ootiib@hot.ee>: Oct 29 11:59AM -0700 On Monday, 24 October 2022 at 17:38:50 UTC+3, JiiPee wrote: > good answer. good point. yes not blindly following a given rule. > But, I wonder why on those videos those expects do not mention so much > about this but its like "this is the elegant way to do it"? It is because swap does not (have conceivable reasons to) throw and so there are no way that copy and swap trashes the object of this. OTOH when this->b = other.b; throws then this->a is tricky to return to what it was. So your straight/old assignment is actually bad/naive in language with exceptions. |
| You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment