clearing cin stream

I have a problem with a program I am writing
initially the segment that I am having trouble with
1
2
3
4
5
6
7
8
for(/*stuff*/)
{
std::string temp;
std::cout<<"\nEnter variable "<<i+1<<": name, type, access.(with spaces(1) and     commas)"<<std::endl<<">>";
std::getline(std::cin, temp);

//other code
}


when the for loop started it would automatically read something in for cin and execute a loop and then for the second iteration it would work properly.

to fix this problem i put std::cin.ignore() before the std::cout<<text line
this would stop the problem of the first iteration, but would require me to hit <return> at the beginning or the other loops.

what I am looking for is a way for cin to clear itself if something is there and do nothing if nothing is there.
I figured out my problem I was using cin>>int in another line of code
I replaced that cin with a getline(cin,str)
Topic archived. No new replies allowed.