If someone has answered correctly and solved my doubt then how to mark it as my answer to question and also mark the whole question as solved?
If someone answered correctly, then simply accept their answer. That'll mark the question as having been answered, and relay to the passing by reader that you as the question asker have found an acceptable answer.
Your question will still be open to other answers as the question ages. If your question gets old enough, your answer may decay, and require an updated answer. Alternatively, another user might have a different solution (or a better one) and post another answer.
If I found the solution myself, then what do I do?
Post an answer to your own question. Someone in the future might have the same issue you did, and would benefit from the solution you found.
If someone from the comments in question has solved my question then what do I do?
Encourage them to post an answer. If they don't, don't be afraid to post your own answer to your question explaining how you solved your problem and mark it as the answer when you can. You can make sure to credit the user who helped you right inside the answer itself if you like.
Every time I flag my question and I ask a moderator to mark it solved but they reject my request.
Moderators cannot mark questions as solved, which is why they declined your flag. It's been requested before, but it was never made to be so.
No question on Stack Exchange is really "solved." Questions can be answered and the question asker (and ONLY the question asker) can mark any of the answers below as the accepted answer, which is about as "solved" as a question can become.
Please do not flag for moderator attention unless absolutely required. Read the help center documentation on flagging to better understand when to flag posts.
I once edited the question by writing it's answer in the question at end and flagged it. Moderator opened my question and removed the solution from my question too.
Please don't do that. Please post it as an answer and accept it, or accept an already posted answer if it solved your problem. Read here for a bit more information on what you should do in that situation.