The code is supposed to accept two strings (or char *) through cin.getline(). But when I run it, it accepts the first string, prints "NO" and exits. Why is it so? Why is the second cin.getline() being skipped?

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

1

How do you inter the strings? What strings do you enter? By the way, this code has a lot memory leaks.
–
Kiril KirovAug 30 '12 at 12:35

DevSolar: The code you gave is also not accepting the strings properly inside the loop. Anyway, I cut the part of main() because I thought it wouldn't matter as my question was about getline().
–
user1657918Aug 30 '12 at 13:11

This is a very poor example. An unchecked input operation is essentially a programming error.
–
Kerrek SBAug 30 '12 at 13:14

@minoz - the code that DevSolar posted does not have a loop. But start from there, and build up to something more like the code you're having problems with. This is a standard debugging technique: get down to something simple that works, and work back up toward the more complex code that doesn't work. I often find that I solve the problem in the course of trying to write code suitable for posting on a forum like this.
–
Pete BeckerAug 30 '12 at 13:16

@minoz: The code works perfectly even if placed in a loop. Since you didn't tell or show us what is expected of the loop, and I am not psychic, I cannot tell what exactly is not working for you.
–
DevSolarAug 30 '12 at 13:27

@KerrekSB: This is a minimal modification of the OP's own example. I am not willing to do full-blown error checking and code-style massaging on proof-of-concept code snippets, and I would thank you for not stalking me for it.
–
DevSolarAug 30 '12 at 13:31

You should always consider it a hard programming and logic error if you perform an input operation whose return value is not immediately used in a boolean context. In my example, the condition check of the for loop tests whether two successive line extractions succeeded, and if not (e.g. if the file stream has reached the end), the loop breaks.