From the home page of this site there is a link to an excellent collection of tutorials. I suggest you read the sections titled Basic Input/Output
and Input/Output with Files
. They are replete with examples.
I suggest that you use getline
() to read an entire line at a time, then use a stringstream
to collect the values from it. An unsigned short
is the smallest data size that will conform with the PGM format's value range.
How do you intend to display the image? (What OS are you using?) Because you cannot display it in the terminal -- you have to be running a GUI of some type.
How you store the image depends on how you intend to display it. For example, if you are programming on MS Windows, you should stick the pixel values into a BITMAP structure.
The other possibility is the create your own image format and draw the image yourself (pixel by pixel) to the output device. An example:
(see my post at the bottom).
Either way, you'll have to spend some time learning how to do it...