Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print text between pointers

I have a character range with pointers (pBegin and pEnd). I think of it as a string, but it is not \0 terminated. How can I print it to std::cout effectively?

  • Without creating a copy, like with std::string
  • Without a loop that prints each character

Do we have good solution? If not, what is the smoothest workaround?

like image 482
Notinlist Avatar asked Nov 16 '25 03:11

Notinlist


1 Answers

You can use ostream::write, which takes pointer and length arguments:

std::cout.write(pBegin, pEnd - pBegin);
like image 180
Magnus Hoff Avatar answered Nov 17 '25 20:11

Magnus Hoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!