- c++中的peek()函数可以返回输入流中的下一个字符而不把这个字符从输入流中取出。
- 利用c中的getc和ungetc实现了c++中类似的功能。
- peek_nextchar()和get_nextchar()返回下一个非空的字符。
char cpeek() {
char ans = getc(stdin);
ungetc(ans, stdin);
return ans;
}
char peek_nextchar() {
char ans;
do {
ans = getc(stdin);
} while(isspace(ans));
ungetc(ans, stdin);
return ans;
}
char get_nextchar() {
char ans;
do {
ans = getc(stdin);
} while(isspace(ans));
return ans;
}