随笔分类 - C++
摘要:#include <iostream> #include <chrono> #include <thread> void printNumbers1() { for (int i = 1; i <= 10000; i++) { std::cout << "Thread 1: " << i << st
阅读全文
摘要:auto 是 C++11 中新增的一种类型推导关键字,可以根据变量的初始化表达式,自动推导出相应的类型。使用 auto 可以简化代码,减少类型错误的发生,提高代码的可读性和可维护性。 下面是 auto 的使用示例,假设我们有一个整数变量 x,可以这样使用 auto 进行类型推导: auto x =
阅读全文
摘要:#include <iostream> #include <vector> int main() { std::vector<std::string> con; con.push_back("9999"); std::cout<<con[0]; return 0; } vector搞了一个多态,你可
阅读全文
摘要:这个也是和Java不同的地方,作用是为了防止类的名字冲突 #include <iostream> namespace myspace{ class A{ public: std::string head; private: std::string body; }; } namespace myspa
阅读全文
摘要:这个是用来include的防止多次重复include #ifndef A_H #define A_H int test(){ } #endif
阅读全文
摘要:#include <iostream> class A{ public: std::string head; private: std::string body; }; int main() { A a; a.head="888"; a.body="999"; return 0; } 报错结果 ma
阅读全文
摘要:#include <iostream> class A{ public: std::string head; void hello(std::string str){ std::cout<<str<<head<<std::endl; } }; int main() { A a; std::strin
阅读全文
摘要:#include <iostream> using namespace std; // 定义一个人的类 class Person { private: int age; // 年龄 float height; // 身高 public: // 构造函数,初始化年龄和身高 Person(int age
阅读全文