When we try to take input from user using cin.getline() function then there is necessary to call cin.ignore function before that line to successfully done that work. Otherwise the program takes the garbage values for the next iteration.

It's not as simple as that, but if you're only using getline() then there should be no need to ignore garbage if you're using getline() correctly. The problem of garbage nearly always stems from reading partial lines or mixing getline with formatted input (in the form of the >> operator).

The latter is explained in painful detail here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.