I’m working with a C API and a lot of the functions take arguments that are character arrays. I’ve heard that using char arrays is now frowned upon. But on the other hand, using c_str() to convert the string to a char array over-and-over seems wasteful.
Are there any reasons to do it one way vs the other?
The
c_str()call is quite likely to be inlined—it’s very small in terms of the required code. I would usestd::stringif that’s the only thing holding you back.Of course, if you’re very worried, this standard advice applies:
Also be aware that this is a micro-optimization; you’re quite likely to be wasting development time worrying about something completely different than from what you should be worrying about.