📄 pex2_2.cpp
字号:
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
void OctIn(unsigned int& n)
{
int base8Value = 0;
char ch;
// skip white space
do
{
ch = cin.get();
}
while (ch == ' ' || ch == '\t' || ch == '\n'); // whitespace
// char should be in range '0'..'7'
if (ch < '0' || ch >= '8')
{
cerr << "Invalid octal input";
exit(1);
}
// convert as long as have octal digit
while (ch >= '0' && ch < '8')
{
base8Value *= 8;
base8Value += ch - '0';
ch = cin.get();
}
n = base8Value;
}
void main (void)
{
unsigned int value;
for (int i = 0; i < 5; i++)
{
OctIn(value);
cout << value << endl;
}
}
/*
<Run>
7 177 127 7776 177777
7
127
87
4094
65535
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -