Search code examples
c++imageimage-processingppm

C++ working with PPM images


I am trying write a function that reads PPM images and the function should return the contents.

PPM images have the following text format:

P3
numOfRows numOfColumns
maxColor
numOfRows-by-numOfColumns of RGB colors

Since the text format has a mixture of variable types, is there any way to store this all in an array? I remembered that C++ does not support arrays with different types. If not, then I am thinking of defining a class to store the PPM contents.


Solution

  • C++ does not support arrays with different types.

    Correct.


    You could:

    1. Define a class as you say, like this: C++ Push Multiple Types onto Vector or this: Creating a vector that holds two different data types or classes or even this: Vector that can have 3 different data types C++.
    2. Have a generic C-like array (or better yet, an std::vector) with void*.