I have a question for you guys, I have provided this code and it works perfectly, But I have a doubt. In lines 31/32(approx.), I have commented a while loop on the right hand side. The thing is if I use that while loop to push the data into the vector, instead of the for loop, the program breaks, somehow the "cin" or something gets carried forward or what happens I have no idea.(You can try for yourself). So Is there some peculiarity of "cin" that I am not aware about.
Thanks for your help in advance.
P.S: I break out-of-the commented while loop by using ctrl-z and enter or entering '|' and then enter.
while ( cin >> temp ) will loop as long as it succeed in reading an integer. When it finds '|' it will fail and the failbit will be set. As long as the failbit is set all read operations from cin will fail, so next time you enter the loop it will leave the loop right away.
To restore cin so that you can read from it again you will have to clear the error flags. cin.clear();
You also need to remove '|' from cin. To remove one character you can do cin.ignore();.
To remove the whole line you can do cin.ignore(numeric_limits<streamsize>::max(), '\n');.