By itself, neither C++ nor its standard library include any functions for dealing with images. To work with images (loading, saving, etc), you need to either do the hard work yourself, or link with a third-party library.
The simplest way is to dump your image to disk in Netpbm format. This format is so simple that you can get away with writing things yourself. There's a library to do that, too. The format does not use any compression, so you will end up with images that are larger than you may expect, but if you're just doing exploratory coding, then it may be good enough.
Other libraries include libjpeg and libpng. Both of these libraries are format-specific (they only work for a certain image format). Libraries that are not format-specific include OpenCV, which actually uses libjpeg and libpng internally.
EDIT
After reading your question, I've realized that your problem isn't just saving the image, it's actually creating it (as well as saving it). The easiest way to "create" an image is to allocate a byte array. Logically, the array is two dimensional: typically, the first dimension corresponds to the height of the image, and the second dimension corresponds to the width. Once you've created your image, you can "draw" on it by setting the values within the array. For example, to draw a line, you enumerate the (x, y) positions on the line, and set the value of the pixel at each position to the desired value.
Finally, when you want to output the image, refer to the first part of my answer.