gpt4 book ai didi

C++ 处理 PPM 图像

转载 作者:行者123 更新时间:2023-11-30 05:30:35 26 4
gpt4 key购买 nike

我正在尝试编写一个读取 PPM 图像的函数,该函数应该返回内容。

PPM 图像具有以下文本格式:

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

由于文本格式混合了变量类型,有没有办法将这些都存储在一个数组中?我记得 C++ 不支持不同类型的数组。如果没有,那么我正在考虑定义一个类来存储 PPM 内容。

最佳答案

C++ does not support arrays with different types.

正确。


你可以:

  1. 按你说的定义一个类,像这样:C++ Push Multiple Types onto Vector或者这个:Creating a vector that holds two different data types or classes甚至这个:Vector that can have 3 different data types C++ .
  2. 拥有一个带有 void* 的通用类 C 数组(或者更好的是,一个 std::vector)。

关于C++ 处理 PPM 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35947757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com