N
N
Nick2282020-05-22 22:03:31
C++ / C#
Nick228, 2020-05-22 22:03:31

How to set a string in C++?

I recently started learning C++ and found two ways to define a string: via an array, and via a variable using string. So, which one is better?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2020-05-22
@Nick228

It really depends on the task at hand. As a rule, std::string works well.
But if you need to work with text in utf-8, interesting nuances begin.
Using arrays for strings is an approach from the C language. It is suitable in those rare cases when you have, for example, the maximum length of a string is limited and the like. In general, if you start using arrays for strings, you'll just rewrite a poorly debugged, suboptimal, and hardly well-tested implementation of std::string all over again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question