CPlusPlus
CPP – Don’t append `\x00` to std::string
Record an experience of debugging. Here are two ways to read string and store it in std::string.One will have ‘\x00’ in std::string object, the other has not.
Record an experience of debugging. Here are two ways to read string and store it in std::string.One will have ‘\x00’ in std::string object, the other has not.
We want to create a file which path looks like /Folder1/Folder2/Folder3/file.txt. The parent directory Folder3 of file.txt has to be there, or the creating action will fail. Similarly, Folder2 and Folder1 need to be on the disk firstly. If you are a Linux OS user, you can use the following Read more…
The function insert of std::map would fail if the key equivalent to the one of an element already in the container.when it happens, the new element is not inserted, and return an iterator to this existing element. Demo: The update can be done successfully if we use operator [] for Read more…
The following content involves the concepts of synchronous and asynchronous. Here is a C++ class that simulates a timer. Output asynchronously. To simulate a timer for sequentially outputting numbers, we can do it like this: We cannot execute the task of rendering frames by creating a new thread in this Read more…
I conducted tests on Windows 10’s WSL to examine the case sensitivity differences in file paths within the home directory (Linux file system) when it comes to recognizing the case sensitivity of paths in C++ code. However, within the /mnt/d directory (Windows file system), case sensitivity is ignored. Project had Read more…
If you are on linux os, you needn’t add library setting in CMakeLists.txt. The libray iconv files has been inside system path. main.cpp
We need to configure project in the project file CMakeLists.txt to support to use shared library or static library.Here is an example to build a project based on the library uchardet. Use shared library Use static library
std::thread #include <iostream> #include <thread> #include <chrono> void f1(int n) { for (int i = 0; i < 5; ++i) { std::cout << “function f1 executing\n”; ++n; std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } void f2(int& n) { for (int i = 0; i < 5; ++i) { std::cout << “function f2 executing\n”; ++n; Read more…
Constexpr : Know Value At Compile Time int main(int argc, char** argv ) { int size0; constexpr auto size1 = 10; //constexpr auto size2 = size0; //error: constexpr variable ‘size2’ must be initialized by a constant expression return 0; } Mark Function Delete To Avoid Data Type Conversion void ShowValue(double Read more…