第5章 语句

1-noskipws,不舍弃空白字符
noskipws
2-tolower,转小写字符
3-cin.eof() 结束符
cin.eof()
4-isupper(), 是否是大写字符
5-cin连续输入


int main(void)
{
    int i, j;
    std::cin >> i >> j;
    if (j == 0)
        throw std::runtime_error("divisor is 0");
    std::cout << i / j << std::endl;

    return 0;
}

6-runtime_error

int main(void)
{
    for (int i, j; cout << "Input two integers:\n", cin >> i >> j; )
    {
        try 
        {
            if (j == 0) 
                throw runtime_error("divisor is 0");
            cout << i / j << endl;
        }
        catch (runtime_error err) 
        {
            cout << err.what() << "\nTry again? Enter y or n" << endl;
            char c;
            cin >> c;
            if (!cin || c == 'n')
                break;
        }
    }

    return 0;
}
上一篇:【蜕变之路】第34天 算法题之一 (2019年3月24日)


下一篇:Springboot基于aop自定义注解(方法耗时)