CPlusPlus
Import Iconv Library Into C++ Project To Convert Charset
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
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…
Get field value by std::get from container We can use std::get to fetch field value from container object. It can help us to avoid use iteractor to access first or second element. #include <iostream> #include <tuple> #include <string> #include <map> #include <vector> using namespace std; using Info = std::tuple<std::string, int, Read more…
The article show demoes about use ifstream to read file written by qfile and use qfile to read file written by ofstream. Use ifstream to read file written by QFile #include <QCoreApplication> #include <QString> #include <QFile> #include <iostream> #include <fstream> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString Read more…
The article is similar to my old post C++: Save Data To A Local File That Humans Can Read. I want to save a little data into a local file that human can’t read it. It is best done conveniently through C Plus Plus.The following example shows the entire logic. Read more…
Rotate Vector To Orthogonal Direction Just like in the picture, we will rotate vector to which is orthogonal to the neighbor . The vector is the cross product of and . #include <iostream> #include “point.hpp” int main() { Point m( 1, 0, 0 ); Point n( 1, 0.5, 0 ); Read more…
I write a few file IO functions which are used in windows and mac os x. bool CopyAFile(const std::string inFile, const std::string outFile); bool RemoveFile(const std::string filePath); void RemoveDir(const std::string folderPath); void MoveAFile(const std::string oldFile, const std::string newFile); void CheckFolderExist(const std::string folderPath); bool FileExists( const std::string path ); void HandleLastSlash( Read more…