#includeusing namespace std; int main() { char input; cin.get(input); if (cin.peek() == ',') { // do something if the next character is a comma } else { // do something else if the next character is not a comma } return 0; }
#includeThis program reads characters from the input stream until it reaches a newline character. It uses peek to check for the newline character without actually reading it, so it can keep reading characters until the end of the line. In both of these examples, the std istream peek function is part of the C++ standard library.using namespace std; int main() { char input; while (cin.peek() != '\n') { cin.get(input); // do something with the input } return 0; }