C转C++的学习条记

打印 上一主题 下一主题

主题 1036|帖子 1036|积分 3108

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
useing namesapce

  1. #include <iostream>//输入输出流
  2. //在前面加c
  3. using namespace std;//std为名称空间
  4. //避免函数重复
复制代码
cin 和 cout

  1. #include <iostream>//输入输出流
  2. //在前面加c
  3. using namespace std;//std为名称空间
  4. //避免函数重复
  5. int main(){        int n = 0;        cin >> n;//输入什么,等价于 scanf("%d", &n);        cout << "hello guet!" << ++n << endl;//输出,endl就是\n        //没有using namespace std;的情况下        //std::cin >> n;//输入什么,等价于 scanf("%d", &n);        //std::cout << "hello guet!" << ++n << std::endl;//输出,endl就是\n        //std::cout << n++ << "\n";        return 0;}//运算速度不如scanf,printf
复制代码
变量声明

  1. //
  2. //int main()
  3. //{
  4. //        int n = 0;
  5. //        cin >> n;
  6. //        for (int i = 0; i < 10; i++)
  7. //        {
  8. //                cout << n << " ";
  9. //        }
  10. //        cout << endl;
  11. //
  12. //        for (int i = 0; i < 10; i++)
  13. //        {
  14. //                cout << n + 1 << " ";
  15. //        }
  16. //
  17. //
  18. //        return 0;
  19. //}
复制代码
bool变量

  1. #include <iostream>
  2. using namespace std;
  3. //еbool
  4. //int main()
  5. //{
  6. //        bool flag = true;
  7. //        bool flag2 = -1;
  8. //        bool flag3 = 0;
  9. //
  10. //        cout << flag << endl;
  11. //        cout << flag2 << endl;
  12. //        cout << flag3 << endl;
  13. //
  14. //        return 0;
  15. //}
复制代码
const界说常量

  1. #include <iostream>
  2. using namespace std;
  3. //宏定义
  4. //int main()
  5. //{
  6. //        const int Max = 150;//看作宏定义
  7. //
  8. //        //Max = 100;不可改变
  9. //
  10. //        cout << Max << endl;
  11. //
  12. //        return 0;
  13. //}
复制代码
string类

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. 字符串拼接
  5. //int main()
  6. //{
  7. //        //string s = "hello";
  8. //        string s = "hello world";
  9. //        string s_sub = s.substr(6, 5);
  10. //        cout << s_sub << endl;
  11. //
  12. //        string s1 = " xixi";
  13. //        string s2 = s + s1;
  14. //
  15. //        //cin >> s;
  16. //        //输入带有空格:
  17. //        getline(cin, s);
  18. //        cout << s << endl;
  19. //        //cout << s2 << endl;
  20. //        cout << s.length() << endl;
  21. //
  22. //        return 0;
  23. //}
复制代码
结构体

  1. #include <iostream>
  2. using namespace std;
  3. //ṹ
  4. //struct stu
  5. //{
  6. //        string name;
  7. //        int age;
  8. //};
  9. //
  10. //
  11. //int main()
  12. //{
  13. //        //Cԣ
  14. //        //struct stu s[10];
  15. //
  16. //        //c++
  17. //        stu a[10];
  18. //
  19. //        return 0;
  20. //}
复制代码
引用&

  1. #include <iostream>
  2. using namespace std;
  3. //void c(int &a)
  4. //{
  5. //        a += 1;
  6. //}
  7. //
  8. //int main()
  9. //{
  10. //        int a = 4;
  11. //
  12. //        c(a);
  13. //
  14. //        cout << a << endl;
  15. //
  16. //        return 0;
  17. //}
复制代码
vector

set

map(键值对)

stack(栈)

queue(队列)

unordered_map和unordered_set

bitset 位运算

sort函数

cctype头文件

C++11特性

auto声明

基于范围的for循环

to_string

stoi stod


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

王海鱼

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表