zoukankan      html  css  js  c++  java
  • C++ 06 语句

    简单语句

    分号结束

    复合语句

    代码块,判断、循环等待

    语句作用域

    语句内部

    if、switch、default、while、for、do-while、break、continue、goto

    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main()
    {
    	int num;
    	while (cin >> num)
    	{
    		if (num == 886) break;
    		if (num == 520) continue;
    		if (num == 69) goto ok;
    		if (num % 2 == 0)
    			cout << num << " is 偶数 " << endl;
    		else
    			cout << num << " is 奇数 " << endl;
    
    	}
    ok:
    	cout << num << " is ok " << endl;
    	return 0;
    }
    

    异常处理 throw、try、catch

    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    double divide(int n1, int n2);
    
    int main()
    {
    	try
    	{
    		double n3 = divide(1, 0);
    		cout << "相除得:" << n3 << endl;
    	}
    	catch (std::runtime_error err)
    	{
    		cout << "相除异常:" << err.what() << endl;
    	}
    }
    
    double divide(int n1, int n2)
    {
    	if (n2 == 0) throw std::runtime_error("被除数不能为0!");
    	return (double)n1 / n2;
    }
    
    
  • 相关阅读:
    MySQL-percona安装
    Oracle-19C PSU升级
    Oracle-内存管理机制
    学习进度第十二周
    十天冲刺10
    单词统计续
    十天冲刺9
    学习进度第十一周
    十天冲刺8
    十天冲刺7
  • 原文地址:https://www.cnblogs.com/hiqianqian/p/6892714.html
Copyright © 2011-2022 走看看