#read file value

44 messages Β· Page 1 of 1 (latest)

humble iron
#

I have this file, and you can see the values in the hex dump.
I have looked at how to use ifstream, but I think that will read it as characters instead of values.
I want to read the values as decimal, and store it into a array. after that I think I can manage.

raw meteorBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

#

@humble iron

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

humble iron
#

the data is the mnist database of handwritten images. so the numbers written are 1 pixel, and range from 0 to 255

zealous mulch
#

use ifstream, read the chars, and use them

zealous mulch
#

decrypting the bytes and parsing them into numbers with a neural network that is trained on hand draw images of numbers, well that's on you

humble iron
#

so I want to read the stream and fill it in a array

humble iron
humble iron
#

I have been able to successfully read the values from the file.
however there is a small prob.

#

when, I run this, i prints as 46831335. however in the hex editor, I can see there are 47040000 bytes. so where did the remaining bytes go?

zealous mulch
#

open ifstream in binary mode

#

and use the function read

#

to extract bytes in your pixel, or your local fixed length array

humble iron
zealous mulch
#

pass a pointer

humble iron
#

here I cant have unsigned char pixel, instead of char pixel

zealous mulch
humble iron
#

working πŸ‘

humble iron
zealous mulch
#

this is how you read bytes into variables

fresh dew
humble iron
#

!solved

raw meteorBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

zealous mulch
# humble iron !solved

calling read and reading 1 char is not very optimal, consider reading larger chunks to improve performance

#

ifstream underneath tries to read in chunks, load them in memory and give you chars one by one from there, but that's a call to read every single time

#

also, your calling of close() is redundant, ifstream has a destructor which will call close for you

#

don't be a C dev, be a C++ dev πŸ™‚

humble iron
zealous mulch
#

allocate memory from the heap first, then run your read

humble iron
#

static char pixels[47040000] ?

#

sorry im new to c++

zealous mulch
humble iron
#

first day

zealous mulch
#

k let me show you

#
std::string buffer(47040000); //roughly 47 megabytes of heap memory 
file.read((char*)&buffer[0], 47040000);
#

check the return value of the read function in an if