Hi,
my program had a requirement to ignore an input beginning with a # sign. The input is entered by user from keyboard. I wanted to know how to use cin.ignore to achieve this.
int main()
{
string str;
cout<<"Enter the string"<<endl;
cin >> str;
cin.ignore( /*I dont know how to use this part*/);
cout<<"Entered string: " <<str <<endl;
}
The output:
Enter the string
# Comment
This is the # comment
string.
The 'str' variable will get some string data in it,in c++ it doesnt get cleared,so to remove the data from the stream one has to use the parameter cin.ignore() to replace the data in the stream with the blank spaces.
Here is the link to the arcticle which can help you
-->http://www.cplusplus.com/forum/articles/6046/