01-04设置cpp

WelcomeToCpp#

  • 使用c++可以控制CPU应该执行的每条指令
  • C++的代码编译后可以在任何平台运行,前提是有一个为对应平台生成机器代码的编译器
  • 与C++不同,C#或JAVA,他们在虚拟机中运行,运行时将代码从“中间语言”转换为机器代码
  • 学习新事物的关键就是对事物进行实验
  • 将讨论如何利用C++库
  • C++实际上如何工作
  • 关于内存和指针:内存区域,智能指针,移动语义,模板
  • 宏,以及为多个平台编程
  • 编写自己的数据结构,学习如何使他们比C++标准库中的结构更快
  • 低级优化,与编译器和汇编相关

设置C++#

windows平台#

  1. 需要文本编辑器,将C++代码编写为文本文件,传递给编译器以生成某种可执行二进制文件,以便可以运行

  2. 或者跳过1,直接用IDE,即有一套帮助你编写和调试代码的工具。(Visual Studio,视频用的2017,我这里下载的 Visual Studio Community 2022)

  3. 安装勾选:

  4. 新建项目

    不要勾选 Place solution and project in the same directory

    解决方案,solution,是一组相互关联的项目,他们有各种项目类型,解决方案就像工作台,每个项目本质上是一组文件,会编译成目标二进制文件(无论是库还是实际的可执行文件)

  5. 添加新项

  6. 代码文件(Main.cpp)

#include <iostream>
int main() {
	std::cout << "hello world!" << std::endl;
	std::cin.get();
}

配置文件修改#

下载ChernoVS.vssettings文件,并放到下面的位置
C:\Users\ly\AppData\Local\Microsoft\VisualStudio\17.0_f89cedea\Settings

在vs工具栏中-tools-ImportAndExportSettings-

ImportSelectedEnvironmentSettings

选择no,just Import new,选择 ChernoVS.vssetings即可

运行#

  1. 右键,构建(项目)


    文件系统查看:

  2. 双击.exe文件,结果:


    按任意键终止


或者单机本地的Windows调试器来运行它

154【杂项】算竞常用_C++_STL_用法

C++ 标准模板库 (STL, Standard Template Library):包含一些常用数据结构与算法的模板的 C++ 软件库。其包含四个组件——算法 (Algorithms)、容器 (Containers)、仿函数 (Functors)、迭代器 (Iterators).

示例:

  • 算法:sort(a.begin(), a.end())
  • 容器:priority_queue<int> pque
  • 仿函数:greater<int>()
  • 迭代器:vector<int>::iterator it = a.begin()

1 前言#

STL 作为一个封装良好,性能合格的 C++ 标准库,在算法竞赛中运用极其常见。灵活且正确使用 STL 可以节省非常多解题时间,这一点不仅是由于可以直接调用,还是因为它封装良好,可以让代码的可读性变高,解题思路更清晰,调试过程 往往 更顺利。

不过 STL 毕竟使用了很多复杂的结构来实现丰富的功能,它的效率往往是比不上自己手搓针对特定题目的数据结构与算法的。因此,STL 的使用相当于使用更长的运行时间换取更高的编程效率。因此,在实际比赛中要权衡 STL 的利弊,不过这一点就得靠经验了。

接下来,我会分享在算法竞赛中常用的 STL 容器和算法,对于函数和迭代器,就不着重展开讲了。

2 常用容器#

2.1 内容总览#

打勾的是本次将会详细讲解的,加粗的是算法竞赛中有必要学习的。

  • 顺序容器

    • array

    • vector

    • deque

    • forward_list

    • list

  • 关联容器

    • set
    • map
    • multiset
    • multimap
  • 无序关联容器

    • unordered_set
    • unordered_map
    • unordered_multiset
    • unordered_multimap
  • 容器适配器

qt学习

建议版本#

  • Qt 4.8.7 官方推荐的 MinGW 版本为 4.4.x,但是MinGW4.4没法编译,MinGW4.5才行,然后找不到MinGW4.5,这里使用了MinGW4.8。qtCreator配套推荐3.0.1(也可以用3.5.0)

下载(视频所用版本)#

- perl-->  https://strawberryperl.com/download/5.16.3.1/strawberry-perl-5.16.3.1-32bit-portable.zip
- MinGW(4.8.1): https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.1/threads-posix/sjlj/i686-4.8.1-release-posix-sjlj-rt_v3-rev2.7z/download (兼容windowsXP)
- (推荐)https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.2/threads-posix/dwarf/ (新版win7以上)
=====qt 4.8.7========
- qt库(带MinGW和qtCreator) :https://download.qt.io/new_archive/qt/4.8/4.8.7/qt-opensource-windows-x86-mingw482-4.8.7.exe
- qt库(源码): https://download.qt.io/new_archive/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.zip
- qtCreator: https://qt.mirror.constant.com/archive/qtcreator/3.0/3.0.1/qt-creator-opensource-windows-x86-3.0.1.exe
===弃用===
- MinGW(4.4): https://www.123912.com/s/u5pSjv-32uAH?提取码:M27Z  
	- 要记得设置环境变量
- qt库: https://download.qt.io/archive/qt/4.7/qt-win-opensource-4.7.0-mingw.exe  
- Qt Creator: https://download.qt.io/archive/qtcreator/2.0/qt-creator-win-opensource-2.0.1.exe  
====使用5.0.2====
qt+mingw--> https://download.qt.io/archive/qt/5.0/5.0.2/qt-windows-opensource-5.0.2-mingw47_32-x86-offline.exe
源码-->  https://download.qt.io/archive/qt/5.0/5.0.2/single/qt-everywhere-opensource-src-5.0.2.zip
=====在线版5.15======
https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/online_installers/qt-online-installer-windows-x64-online.exe
- .\qt-online-installer-windows-x64-online.exe  --mirror https://mirrors.ustc.edu.cn/qtproject 
- Archive中选择5.15及6.8
- 安装内容:MinGW,Android,QtCharts,QtMultimedia,QtQuich3D,QtShaderTools
=====其他=======
- qt库(带MinGW和qtCreator): https://download.qt.io/new_archive/qt/5.2/5.2.1/qt-opensource-windows-x86-mingw48_opengl-5.2.1.exe

编译静态编译的qmake#

  • 下载源码
  • 路径不能有奇奇怪怪的符号(.-_ 之类)
  • (弃)修改 E:\Qt\qtSrc\qtbase\mkspecs\win32-g++\qmake.conf,修改QMAKE_LFLAGS = -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc(仅添加-static)

目录结构#

#mkdir "E:\Qt\qtCustom487\buildQtStatic" #/p
mkdir "E:\Qt\qtCustom\buildQtStatic" #/p
#mkdir "E:\Qt\qtCustom487\qtStatic" #/p
mkdir "E:\Qt\qtCustom\qtStatic" 
#mkdir "E:\Qt\qtCustom487\qtSrc" #/p
mkdir "E:\Qt\qtCustom\qtSrc"  
#E:\Qt\qtCustom下
				- buildQtStatic #(新建的)编译时切换到这个目录
				- qtSrc #源码
				- qtStatic #(新建的)install目录

静态编译#

我用的是视频0087集的办法,也可以用 https://www.cnblogs.com/atggg/p/16878575.html试试