Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用 读取单个扩展 ASCII 字符cin.get()。我想使用cin.get()这样我也可以在输入中读取空格等。我发现我需要使用无符号字符来存储字符,但无符号字符cin.get()似乎不能一起工作。有没有办法做到这一点?
cin.get()
基本上,我一直在尝试做这样的事情:
unsigned char c; while (cin.get(c)) { //do stuff with c .... }
有没有办法做到这一点?
尝试这个
unsigned char c; while ( (c = cin.get()) != EOF ) { //do some stuff }
您可以再尝试一件事来读取 255 个 ASCII 字符:
int ch; unsigned char c; while ( (ch = cin.get()) != EOF ) { c = (unsigned char)(ch); // do some stuff }