C++面向对象基础
访问控制限定符 public: 谁都可以访问 protected(默认): 只有自己和派生类可以访问 private: 只有自己可以访问 类和结构体的区别 类有访问限定符,结构体没有 创建类,对象 1234567891011121314151617181920class Dog { string name;public: void eat();};// 栈区对象Dog dog1;Dog dog1[4];// 堆区对象Dog* dg1 = new Dog;dg1->eat();delete dg1;dg1 = NULL;Dog* dg2 = new Dog[3];dg2[0].eat();delete[] dg2;dg2 = NULL; string 类 查找 s1.find(查找的字符串,开始位置); 替换 s1.replace(开始替换位置,替换的位数,替换字符串); 12s1 = "1234567";s1.replace(s1.find("456"), 2, "abc"); // 1...
c++基本概念
新建C++的工程 1 新建项目,控制台应用程序 勾选空项目, 勾去安全周期检查 2 源文件 –> 新建项 3 添加main.cpp 4 选择性编译 123456789#if 0#include <stdio.h>int main() { printf("Hello World"); return 0;}#endif 命名空间 (namespace) 在同样的作用域下不能定义多个同名变量或者函数 所以可以使用命名空间来解决这个问题 命名空间可以嵌套 12345678910111213141516171819202122#include <iostream>using namespace std;namespace yf { int a = 12;}namespace fy { int a = 1; namespace ffy{ int a = 11; }}int main() { cout << fy::...