Having difficulty writing into a file

Use UserDefaults instead of fstream.
It’ll be one line code each for reading and saving data.

If you want SQLite, then that’s something else. But the thing, you’re asking, cocos2d-x support out of the box.

Or else, you can check
http://www.cocos2d-x.org/docs/programmers-guide/advanced_topics/index.html#functions-to-read-file-content