{"id":16521137,"url":"https://github.com/bmalbusca/cplus2_tutorial","last_synced_at":"2025-09-09T08:37:06.927Z","repository":{"id":111990587,"uuid":"287989102","full_name":"bmalbusca/cplus2_tutorial","owner":"bmalbusca","description":"Modern C++ tutorial","archived":false,"fork":false,"pushed_at":"2020-09-11T19:54:06.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T01:16:31.344Z","etag":null,"topics":["cmake","tutorial"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bmalbusca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"bmalbusca","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-08-16T17:11:44.000Z","updated_at":"2020-09-11T19:54:09.000Z","dependencies_parsed_at":"2023-07-30T16:31:26.511Z","dependency_job_id":null,"html_url":"https://github.com/bmalbusca/cplus2_tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bmalbusca/cplus2_tutorial","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmalbusca%2Fcplus2_tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmalbusca%2Fcplus2_tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmalbusca%2Fcplus2_tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmalbusca%2Fcplus2_tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bmalbusca","download_url":"https://codeload.github.com/bmalbusca/cplus2_tutorial/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmalbusca%2Fcplus2_tutorial/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274268372,"owners_count":25253386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","tutorial"],"created_at":"2024-10-11T16:54:14.530Z","updated_at":"2025-09-09T08:37:06.868Z","avatar_url":"https://github.com/bmalbusca.png","language":"C","readme":"# C++ quick tutorial (Cheat Sheet)\n\n#### Other sources\n- [Complete tutorial - **RECOMMENDED**](https://daveparillo.github.io/intermediate-cpp/index.html)\n- [C++ quick review (5min)](https://www.youtube.com/watch?v=8wnj6M-jj9c\u0026t=222s)\n- [Multithreading (21min)](https://www.youtube.com/watch?v=3aqxaZsvn800)\n\n\n# Standard IO\n\n- ``stdout``: channel 1\n- ``stderr``: channel 2\n\n#### Redirecting\n\n**to ``stdout``is**:\n\u003e\n\u003e ``command 1\u003e out.txt``\n\u003e\n\u003e or ``command \u003e\u003e out.txt``\n\u003e\n\n**to ``stderr`` is**:\n\u003e\n\u003e ``command 2\u003e out.text``\n\u003e\n\n\u003e **to both:** `` program \u003e out.txt 2\u003e\u00261`` or in different files using ``program 1\u003estdout.txt 2\u003estderr.txt``\n\u003e\n\n## Chaining commands\n- ``cmd1; cmd2`` - call 1 after another\n- `cmd1 \u0026\u0026 cmd2` - the same as before but fails if some returns non-zero code\n- `cmd1 | cmd2` - piping stdout of cmd1 to stdin cmd2\n\n### Example\n find smith :  ``ls | grep smth``\n\n\n## C++ IO streams - `#include \u003ciostream\u003e`\n\n - ``std::cin`` - stdin\n - ``std::cout`` - stdout\n - ``std::cerr`` - stderr\n\n\u003e **Note**\n\u003e\n\u003e - ``\u003e\u003e``  in \n\u003e\n\u003e - ``\u003c\u003c``  out\n\n# C++ Libraries\n\n### Strings\n- ``#include \u003cstring\u003e`` to use ``std::string``\n- concatenate with **``+``**\n- check if empty using ``str.empty()``\n\nexamples: \n\n```c  \n\tstd::string hello = \"Hello\"; \n    std::cout \u003c\u003c hello + \"Bruno\" \u003c\u003c std:endl;\n\n```\n\n\n\n### Arrays - Fixed size\n- ``#include \u003carray\u003e`` to use ``std::array``\n- store collections of items of same type and fixed size: `` array\u003cfloat3\u003e\narr = {1.0f,2.0f,3.0f}``\n- ``arr.size()``;`` arr.clear()``; ``arr.front()``;`` arr.back()``\n\n\n### Vectors - Dynamic table, usefull when you don't know the size\n- ``#include \u003cvector\u003e`` to use std::vector\n- **use the same methods as array**\n- ``vec.emplace_back(value)`` can be more efficient than ``vec.push_back(value)``\n- to optimize vector resizing use ``reserve(n)``\n- `vec.insert(,)` is also available such the `iterator()`\n\n\n\n# C++ features \n\n#### For loop\n- similar to ``foreach()`` in Java, here we have ``for(float num: vector)`` \n\n#### Function overloading\n```c \n\tstring Fun(int n){return \"int\";}\n    string Fun(const string\u0026 str){return \"string\";} \n```\n\n\n### Scopes\n- easy example: \n```c \n\t\tfloat  some_float=13.3f;\n        { // New inner scope\n            auto another_float = some_float; // copy\n        }//another_float dies\n```\n### References\n- Use **\u0026** to state that a variable is a reference\n- ``float\u0026 ref = original_variable;`` ref has type float\u0026\n- use ``const`` references as a funtion argument type for non fundamental variables types\n\n\n# More tips\n\n\n##  1. ***CMAKE*** makefiles \n\n- create folders  ``build`` and ``src`` and a ``CMakeLists.txt`` file at the parent folder; \n\n- to execute CMAKE you need to give  the `CMakeLists.txt` path, for example ``build/$~ cmake ..`` . Follow the typical set of instructions for the project. \n\n- To all subdirectories that we added, another CMakeLists need to exists there and they can be empty! ``${PROJECT_SOURCE_DIR}/`` is a system variable that is usefull to set a full path; \n    \n- At the end, we need to add a executable in the CMakeLists at `src` folder : ``add_executable(main_bin main.cpp)`` ; Then we can use only ``make`` at build folder unless if we added new files after making cmake. A new `src` folder will appear inside `build` folder with the executable file\n\nfrom [this issue](https://github.com/OpenRCT2/OpenRCT2/issues/10355) :\n- Tested working hotfix would be adding following lines somewhere in the head of CMakeLists.txt:\n```bash \n\nIF(APPLE)\n   LINK_DIRECTORIES(/usr/local/lib)\nENDIF()\n```\n\u003e **Look for libraries**\n\u003e \n\u003e arc dynamic/static libraries\n\u003e\n\u003e use ``#pragama once`` at header files \n","funding_links":["https://liberapay.com/bmalbusca"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmalbusca%2Fcplus2_tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbmalbusca%2Fcplus2_tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmalbusca%2Fcplus2_tutorial/lists"}