Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // example of filling the input buffer, clearing it to the end of the line so the user
- // can't miss entering the string due to the left over enter in the first use of cin
- #include<iostream>
- #include<limits>
- int main(int argc, const char* argv[]){
- // filling the buffer with data
- int x;
- std::cin >> x;
- // clearing the buffer and warning flags to the end of the line
- std::cin.clear();
- std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
- // filling buffer with string data
- std::string s;
- getline(std::cin, s);
- // clearing the buffer to the end of the file
- std::cin.clear();
- std::cin.ignore(std::numeric_limits<std::streamsize>::max());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement