Hello I'm making an application that reads a series of values from a text file and then converts it to a bitmap image.

Currently, I'm using arrays, but, deciding on a particular length is annoying.

I have been reading a few tutorials and i've read a lot about using vectors, which, I am happy to do so. But my question is this:

Can I use a vector like this:

vector<pixel> myImage;

Each binary digit in the text file represents a pixel in the Bitmap image?

Thanks :)

If you want to read the file into a vector, then you can represent each pixel as a char or int. For example you can have something like so, std::vector<char> pixels; and read from file into that vector. For example:

std::vector<char> pixels;
ifstream fileInput("imagefile.txt");
//read from file into vector
std::copy( std::istream_iterator<char>(fileInput), 
                std::istream_iterator<char>(),
                std::back_inserter(pixels));

for(int i = 0; i < pixels.size(); ++i){
  cout << pixels[i];
}

Hey thank you for your reply :)

I'm using something simular to that.

Just out of interest though: Vectors OR arrays for image manipulation?

Personally I want to use Vectors and only really use arrays when needed.

Use std::vector whenever possible, only use static arrays, when you absolutely need to

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.