Question: I m writing a c++ program using files and i need to take the input from existing files such as doc files and pdf files. how to program it in c++? And after getting the inputs, how can i write those details into a new doc or pdf files? Can anyone explain me with an example?

Answer: 
C++ as a language doesn't equip you with such features as "write to DOC file" or "read from PDF file". The only staff available to you a a programmer is raw byte-by-byte reading or writing. To make your new brand file as PDF/DOC/etc compatible you have to conform the chosen file format. The same about reading - you should understand which portions of raw byte array are responsible for what.

In common, this task named as "parsing" or "serialization". And it's a good idea to use one of existing parsers for particular file format instead of reinventing the wheel. Moreover, some file formats can be patent-pending so you may be not allowed to deal with it without license purchase.

Some clues so far: 

* [PDF parsing in C++ (PoDoFo)](https://stackoverflow.com/questions/11715561/pdf-parsing-in-c-podofo)
* [Microsoft word Text Parser in "C"](https://stackoverflow.com/questions/301132/microsoft-word-text-parser-in-c)
There are some libraries available on the web now(the question is from 2013, maybe that time there weren't many).

Apart from the links in selected answer, you can try PDFTron. It also supports new features, eg. Linearization.

Here is one of their samples is ->
<https://www.pdftron.com/documentation/samples/cpp/TextExtractTest>

(That program itself contains 4 if blocks, with slightly different features of the library/SDK, to try)

There should be more, search on the web for PDF parsing libraries.