From 094188777b25309de4439bdd9965ef5afac32a49 Mon Sep 17 00:00:00 2001 From: Nikolay Neupokoev Date: Sat, 27 Jul 2024 21:53:37 -0700 Subject: [PATCH] Just add code to pages --- .vscode/settings.json | 23 ++++++++++++++++++++++- src/basics/constness.md | 10 +++++++++- src/basics/files.md | 13 +++++++++++++ src/basics/leaks/README.md | 4 ++++ src/basics/leaks/containers.md | 4 ++++ src/basics/leaks/map.md | 1 - src/basics/leaks/stdmap.md | 4 ++++ src/basics/pointers/arguments.md | 22 ++++++++++++++++++++++ 8 files changed, 78 insertions(+), 3 deletions(-) delete mode 100644 src/basics/leaks/map.md diff --git a/.vscode/settings.json b/.vscode/settings.json index 256bbf2..e188f65 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -88,7 +88,28 @@ "ranges": "cpp", "filesystem": "cpp", "text_encoding": "cpp", - "*.inc": "cpp" + "*.inc": "cpp", + "ios": "cpp", + "locale": "cpp", + "queue": "cpp", + "stack": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xstddef": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "__nullptr": "cpp" }, "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" } \ No newline at end of file diff --git a/src/basics/constness.md b/src/basics/constness.md index cd37a5a..3a32370 100644 --- a/src/basics/constness.md +++ b/src/basics/constness.md @@ -2,24 +2,32 @@ ## Arrays and pointers +### Intact values + Values of the array cannot be changed. But array itself can be assigned ```cpp {{#include ../../basics/constness/const-1.cpp}} ``` +### Intact pointer + This preserves the pointer but not the values ```cpp {{#include ../../basics/constness/const-2.cpp}} ``` +### Initialize only once + It must be assigned only once ```cpp {{#include ../../basics/constness/const-3.cpp}} ``` +### Read-only + Here's the absolute read-only version ```cpp @@ -27,7 +35,7 @@ Here's the absolute read-only version ``` -## When function call changes the pointer +## When function changes the pointer Wrong diff --git a/src/basics/files.md b/src/basics/files.md index 1033a16..2f34f6e 100644 --- a/src/basics/files.md +++ b/src/basics/files.md @@ -1 +1,14 @@ # Files + +## Get file content + +```cpp +std::ifstream in(filename, std::ios::in | std::ios::binary); +if (!in) { + std::cerr << "could not open " << filename << std::endl; + return 1; +} +std::ostringstream contents; +contents << in.rdbuf(); +std::string ogg_data = contents.str(); +``` \ No newline at end of file diff --git a/src/basics/leaks/README.md b/src/basics/leaks/README.md index ace6873..7ab4ba7 100644 --- a/src/basics/leaks/README.md +++ b/src/basics/leaks/README.md @@ -1 +1,5 @@ # Leaks + +```cpp +{{#include ../../../basics/pointing_arguments/cleaning.cpp}} +``` \ No newline at end of file diff --git a/src/basics/leaks/containers.md b/src/basics/leaks/containers.md index feddda2..4cdd475 100644 --- a/src/basics/leaks/containers.md +++ b/src/basics/leaks/containers.md @@ -1 +1,5 @@ # Raw pointers + +```cpp +{{#include ../../../basics/raw_pointers/raw-pointer-container.cpp}} +``` \ No newline at end of file diff --git a/src/basics/leaks/map.md b/src/basics/leaks/map.md deleted file mode 100644 index dd56773..0000000 --- a/src/basics/leaks/map.md +++ /dev/null @@ -1 +0,0 @@ -# Weird Map diff --git a/src/basics/leaks/stdmap.md b/src/basics/leaks/stdmap.md index dd56773..742803f 100644 --- a/src/basics/leaks/stdmap.md +++ b/src/basics/leaks/stdmap.md @@ -1 +1,5 @@ # Weird Map + +```cpp +{{#include ../../../basics/weird_map/weird-map.cpp}} +``` \ No newline at end of file diff --git a/src/basics/pointers/arguments.md b/src/basics/pointers/arguments.md index b6681ba..38238b3 100644 --- a/src/basics/pointers/arguments.md +++ b/src/basics/pointers/arguments.md @@ -1 +1,23 @@ # Pointing arguments + +```cpp +{{#include ../../../basics/pointing_arguments/pointing.cpp}} +``` + +## C style + +```cpp +{{#include ../../../basics/pointing_arguments/c-style.cpp}} +``` + +## By reference + +```cpp +{{#include ../../../basics/pointing_arguments/by-reference.cpp}} +``` + +## C++ style + +```cpp +{{#include ../../../basics/pointing_arguments/cpp-style.cpp}} +```