从C到C++
学习C++中C没有的功能
Trstary
每天掉一根,知识涨一截。
展开
-
十.带默认值的函数参数(从C到C++)
内容参考于《21天学通C++》(第八版)十.带默认值的函数参数1. 示例1()#include <iostream>using namespace std;// Function Declarations (Prototypes)double Area(double radius, double pi = 3.14){ return pi * radius * radius;}int main(){ cout << "Enter radius: ";.原创 2020-09-18 13:38:47 · 115 阅读 · 0 评论 -
九.动态内存分配(从C到C++)
内容参考于《21天学通C++》(第八版)九.动态内存分配1. 示例1#include <iostream>using namespace std;int main(){ // Request for memory space for an int int* pointsToAnAge = new int; // Use the allocated memory to store a number cout << "Enter your dog’ s age:.原创 2020-09-17 14:49:32 · 86 阅读 · 0 评论 -
七.引用(从C到C++)
内容参考于《21天学通C++》(第八版)七.引用(从C到C++)1. 示例1#include <iostream>using namespace std;int main(){ int original = 30; cout << "original = " << original << endl; cout << "original is at address: " << hex << &or.原创 2020-09-17 14:40:03 · 92 阅读 · 0 评论 -
八.lambda函数(匿名函数)(从C到C++)
内容参考于《21天学通C++》(第八版)七.lambda函数(匿名函数)1. 示例#include <iostream>#include <vector>using namespace std;void ForEach(const std::vector<int> &values, void(*func)(int)){ for (int value : values) func(value);}int main(int argc,.原创 2020-09-17 14:21:10 · 95 阅读 · 0 评论 -
六.函数重载(从C到C++)
内容参考于《21天学通C++》(第八版)五.函数重载1. 示例#include <iostream>using namespace std;const double Pi = 3.14159265;double Area(double radius); // for circledouble Area(double radius, double height); // for cylinderint main(){ cout << "Enter z fo.原创 2020-09-17 14:03:37 · 86 阅读 · 0 评论 -
五.C++字符串std::string(从C到C++)
内容参考于《21天学通C++》(第八版)五.C++字符串std::string1. 示例#include <iostream>#include <string>using namespace std;int main(){ // 创建有初始值的字符串 string greetString("Hello std::string!"); cout << greetString << endl; // 创建空字符串,并获取值 cout.原创 2020-09-17 12:00:26 · 146 阅读 · 0 评论 -
四.动态数组(从C到C++)
内容参考于《21天学通C++》(第八版)四.动态数组1. 示例#include <iostream>#include <vector>using namespace std;int main(){ vector<int> dynArray(3); // dynamic array of int dynArray[0] = 365; dynArray[1] = -421; dynArray[2] = 789; cout << .原创 2020-09-17 11:50:47 · 80 阅读 · 0 评论 -
三.constexpr关键字(从C到C++)
内容参考于《21天学通C++》(第八版)三.constexpr关键字1. 示例#include <iostream>constexpr double GetPi() { return 22.0 / 7; }constexpr double TwicePi() { return 2 * GetPi(); }int main(){ using namespace std; const double pi = 22.0 / 7; cout << "constan.原创 2020-09-17 11:11:33 · 94 阅读 · 0 评论 -
二.auto关键字(从C到C++)
内容参考于《21天学通C++》(第八版)二.auto关键字1. 示例#include <iostream>using namespace std;int main(){ auto coinFlippedHeads = true; auto largeNumber = 2500000000000; cout << "coinFlippedHeads = " << coinFlippedHeads; cout << " , sizeof.原创 2020-09-17 10:52:54 · 102 阅读 · 0 评论 -
一.命名空间(从C到C++)
内容参考于《21天学通C++》(第八版)一.命名空间1.先查看第一个C++代码1: // Preprocessor directive that includes header iostream2: #include <iostream>3:4: // Start of your program: function block main()5: int main()6: {7: /* Write to the screen */8: std::cout .原创 2020-09-17 09:37:52 · 83 阅读 · 0 评论