https://www.bilibili.com/video/av40959422?p=3
從C到C++快速入門(2019版C++程序設計)
1.
條件編譯
#if 1
#if 0
#endif ?
2.
3.標準名字空間std
std::cout
using namespace std;
cout<<XX; //輸出
cin>> XX; //輸入
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
ofstream oF("test.txt");
oF << 3.14 << " " << "hello world\n";
oF.close();
ifstream iF("test.txt");
double d;
string str;
iF >> d >> str;
cout<<d <<" "<< str<<endl;
return 0;
}
4.文件輸入輸出流
5.引用變量
類似指針,但不是指針
5.函數的默認形參
6.函數重載
7.函數模板
8.string
9.vector
10.動態內存分配
11.面向對象編程
12.作業
/* 輸入一組學生成績(姓名和分數),輸出:平均成績、最高分和最低分。 當然,也要能輸出所有學生信息 */
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct student{
string name;
double score;
void print();
};
void student::print() {
cout << name << " " << score << endl;
}
int main() {
/* student stu; stu.name = "Li Ping"; stu.score = 78.5; stu.print(); */
vector<student> students;
while (1) {
student stu;
cout << "請輸入姓名 分數:\n";
cin >> stu.name >> stu.score;
if (stu.score < 0) break;
students.push_back(stu);
}
for (int i = 0; i < students.size(); i++)
students[i].print();
double min = 100, max=0, average = 0;
for (int i = 0; i < students.size(); i++) {
if (students[i].score < min) min = students[i].score;
if (students[i].score > max) max = students[i].score;
average += students[i].score;
}
average /= students.size();
cout << "平均分、最高分、最低分:"
<< average << " " << max << " " << min << endl;
}
13.
14
15
16