• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Striving_Life
博客园    首页    新随笔    联系   管理    订阅  订阅

C++学习笔记

#include <iostream>//inputstream  outputstream合并缩写,输入输出流的头文件,标准库设计者提前写好的类和类型、宏
#include <Windows.h>
#include<String>
using namespace std;
#pragma region 申明函数
//申明函数
void funcout();
void funcout(string str);
int getMax(int a, int b);
int getMax(int *arr, int arrCount);
int addNum(int number);
#pragma endregion

int main(void)//主函数
{

    int arr[7] = { 2,5,7,8,5,4,7 };
    try
    {
#pragma region test1--输入输出流
        int age;
        string str;
        cin >> str >> age;
        cout << str << "成立" << age << "年了!" << endl;//endl 是endline缩写,换行作用,可用\n代替
        cout << str << "成立" << age << "年了!\n";
#pragma endregion

#pragma region test2--函数调用
        funcout();
        funcout("有参数方法");

        cout << "较大值为:" << getMax(arr[0], arr[1]) << endl;
        cout << "最大值为:" << getMax(arr, 7) << endl;
        cout << "最大值为:" << addNum(7) << endl;
#pragma endregion
    }
    catch (const std::exception& ex)
    {
        throw ex;
    }
    system("pause");//暂停
    return 0;
}

#pragma region test3--函数

void funcout()
{
    cout << "www.c++学习网" << endl;
}
void funcout(string str)
{
    cout << "www.c++学习网" << str << endl;
}
int getMax(int a, int b)
{
    return (a > b) ? a : b;
}
int getMax(int *arr, int  arrCount)
{
    int max = arr[0];
    for (int i = 1; i < arrCount; i++)
    {
        max = (arr[i] > max) ? arr[i] : max;
    }
    return max;
}
int addNum(int number)
{
    int sum=0;
    for (int i = 1; i <= number; i++)
    {
        sum += i;
    }
    return sum;
}
#pragma endregion

 

posted @ 2019-12-03 18:59  Striving_Life  阅读(140)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3