Using iterators with the C Standard Library

The C Standard Library will often require pointers to data. For example, when a C function requires a string, it will need a const char* pointer to the character array containing the string. The C++ Standard Library has been designed to allow you to use its classes with the C Standard Library; indeed, the C Standard Library is part of the C++ Standard Library. In the case of string objects, the solution is simple: when you need a const char* pointer, you simply call the c_str method on a string object.

The containers that store data in contiguous memory (array, string, or data) have a method called data that gives access to the container's data as a C array. Further, these containers have [] operator ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.