Home c++ How does c_str () in C++?

How does c_str () in C++?




I am interested in how the array looks like to which the pointer stands.

I understand that the function takes the string for example string str = “12345” and turns into an array of charms {‘1’, ‘2’, ‘3’, ‘4’, ‘5’, \ 0} and then returns the pointer On this array

or so {“12345”}?

And another time, if returns the pointer, then why it works:

cout & lt; & lt; str.c_str () & lt; & lt; endl;

Answer 1, Authority 100%

As far as I understand, String :: C_STR Returns the pointer to the memory area where the row itself stores. That is, when returning does not create any additional arrays, nothing transforms anywhere and does not copy.

about COUT & LT; & lt; str.c_str () & lt; & lt; endl; : Cout Excellent displays pointers like CHAR * or Const Char * Like lines. You will not embarrass the COUT & LT; & LT; "12345" & lt; & lt; Endl;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions