Sujet : Re: Tabs As Syntax
De : OFeem1987 (at) *nospam* teleworm.us (Chris Ahlstrom)
Groupes : comp.os.linux.advocacyDate : 22. Mar 2024, 20:03:16
Autres entêtes
Organisation : None
Message-ID : <utkh57$32kac$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : slrn/1.0.3 (Linux)
candycanearter07 wrote this copyrighted missive and expects royalties:
Chris Ahlstrom <OFeem1987@teleworm.us> wrote at 12:20 this Friday (GMT):
rbowman wrote this copyrighted missive and expects royalties:
>
On Thu, 21 Mar 2024 10:10:33 -0400, Chris Ahlstrom wrote:
>
for (int n : { 2, 4, 6, 8 })
std::cout << n << ", ";
std::cout << "who do we appreciate?" << std::endl
(std::endl is \n with a flush.
>
cout never did much for me either. That's one of the areas that seemed
like a gratuitous departure from C.
>
Then there is the Python
>
print("Never again!", end="\r")
>
operator << is useful with std::ostringstream when you want to avoid having
deal with allocating enough output space. Still, I use this a lot:
>
char temp[32];
snprintf(temp, sizeof temp, "We have %d idiots here", idcount);
>
Sometime a printf specification is just easier to read.
>
The GNU compiler will even warn if the buffer isn't big enough to hold
the largest possible result.
>
Using C syntax in CPP isn't best practice though.
Well, I could write it as:
#include <cstdio>
char temp[32];
(void) std::snprintf(temp, sizeof temp, "We have %d idiots here", idcount);
:-D
I will use whatever is convenient, easy-to-code and easy-to-read, and safe;
it's a judgment call.
And there are tons of C-only functions out there. Sometimes I will write
a C++ wrapper (or a member function) for some of them. So many decisions to
make!
-- Q: What's the difference betweeen USL and the Graf Zeppelin?A: The Graf Zeppelin represented cutting edge technology for its time.