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