zoukankan      html  css  js  c++  java
  • 【C++】简介与环境的搭建

    版权声明:本文为博主原创文章,转载请注明出处。 https://www.cnblogs.com/YaoYing/p/13162250.html

    前言

    我是主学C的,有了一定的编程基础。而且大学的时候也简单的学过C++,现在相对来说会比较轻松。
    如果是刚入门的,没有编程基础的,个人建议可以去看一些大神的教学视频或者看一些好的教学资料,让自己更加系统地去学习C++。
    因为公司用的设备是树莓派,所以以下所有程序都运行在树莓派上。如果出现一些不兼容问题,我再重新修改。

    特性:

    封装 抽象 继承 多态

    环境

    我是直接用的树莓派(基于Linux)作为开发环境,如果是在Windows系统上编译,需要安装Visual C++等集成开发环境。

    使用g++ -v来查看树莓派下的g++编译器版本号

    pi@raspberrypi:~ $ g++ -v
    Using built-in specs.
    COLLECT_GCC=g++
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/8/lto-wrapper
    Target: arm-linux-gnueabihf
    Configured with: ../src/configure -v --with-pkgversion='Raspbian 8.3.0-6+rpi1' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --disable-werror --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
    Thread model: posix
    gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1)
    

    编译

    C++程序的源文件通常使用扩展名.cpp.cc

    #include <iostream>
    using namespace std;
    int main()
    {
        cout << "Hello, world!" << endl;
        return 0;
    }
    

    也可以写成

    #include <iostream>
    using namespace std;
    int main()
    {
        cout << "Hello, world!
    ";
        return 0;
    }
    

    两种编译方法:

    gcc hello.cpp -lstdc++ -o hello
    g++ hello.cpp -o hello
    

    g++将gcc默认语言设为C++,链接时自动使用C++标准库

    使用-o选项指定可执行程序的文件名

    更新日期20200721
    如有错误之处,请评论或者私信指出,非常感谢

  • 相关阅读:
    NIO中几个非常重要的技术点
    NIO的epoll空轮询bug
    mysql支持跨表删除多条记录
    使用Fastjson生成Json字符串少字段属性(数据丢失)
    Linux系统下安装rz/sz命令及使用说明
    Slave_SQL_Running: No mysql同步故障
    二次幂权限设计
    spring容器加载完毕做一件事情(利用ContextRefreshedEvent事件)
    XStream别名;元素转属性;去除集合属性(剥皮);忽略不需要元素
    JDBC通用DAO
  • 原文地址:https://www.cnblogs.com/YaoYing/p/13162250.html
Copyright © 2011-2022 走看看