How to read and write directory or file contents in c++ ?

Dear Friends,

I m beginner unix programmer. I want to know, how to read and write directory or file contents in c++ ?

I recommend you to look at code of ls.
It is open source. If you are using open soure OS, source of ls should come in the distributive.

Anyway there is good explanation and links to source: ls - Wikipedia, the free encyclopedia

Understanding ls is very good way to start doing what you want.

About file contents, there are good functions for that, for example fopen.

Same as in C really.

opendir/readdir/closedir to read directories.

open/creat/read/write/lseek/close to read and write files.

There is no API to write directory metadata - the kernel does all of it. open, close, unlink, chown, chmod etc. all ultimately result in changes to metadata. What you are calling "write to directories"