c++ Json Lesson. Open office setting. People listening attentively to a seated leader

C++ Json

C++ Json libraries There are at least 3 major, well used c++ json libraries used for reading and writing to json data structures. Our plan is not to use any of them. We are going to first focus on what a json structure looks like, then look at how we might traverse such a structure in much the same way that a javascript coder might do so. But for those who are looking for a c++ json reader that...
Read More
c++ Json Lesson. Open office setting. People listening attentively to a seated leader

C++ file io – Part 2

The CSV format - c++ file io In the last article, we were looking at this csv file format that was contrived into the coding below. There are definitely better ways of doing these things, but that was a quick dirty test. Lets do it better, but first lets once more show the contrived version. #include <fstream> using namespace std; int main(){ string st1 = "'George','Stevens',89,56,90,85\n";...
Read More

C++ enum sample code

enum colors{ red, green, blue};std::cout << "Red " << red << " Green " << green << " Blue " << blue << "\n"; enum is short for enumeration and in this process a list is assigned numerical values, each item in the list, one more than the item before it. If one arbitrarily assigns a value of 4 to an enum item, the next item will be 5 // Example...
Read More

C++ Class Examples

C++ class constructorclass Entity{ public: private: Entity();} /* Lesson Setting up a Class. Several ways to do so. Constructor parameters or initial vars in the public class Author : Trevor Weir Date : Mar 19, 2019 ( 1st day of spring ) */ #include <string> #include <iostream> class Entity{ private: int m_score; std::string m_name; public: Entity() :m_score(0), m_name("unknown"){};...
Read More

C++ Pointers and References

int var = 10;int *ptr;ptr = &var;std::cout << "Address of var is " << &var << std::endl;std::cout << "Value of var is " << *ptr << std::endl; Why we need C++ Pointers and References C++ pointers are not difficult to learn. In truth, there are a few C++ tasks that are performed more easily with pointers, and other C++ tasks, such as dynamic memory...
Read More

C++ Math – Your Fav Topic

C++ Math Functions Examples #include <cmath> You can copy this code below. In most of these examples, we encourage users to copy the code below. // Math your fav topic #include <iostream> #include <cmath> using namespace std; int main(){ cout << "sqrt(144) = " << sqrt(144) << endl; cout << "round(2.65) = " << round(2.65) << endl; cout <<...
Read More
c++ thread tutorial with sample codes

C++ Array of Ints / Integers

#include <array>std::array<int,4> myGrades = {86,80,64,91}; Sample c++ Array of ints Code // std::array usage std::array<int,4> myGrades = {86,80,64,91}; #include <iostream> #include <array> using namespace std; int main(){ float sum = 0.0f; std::array<int,9> myGrades = {86,80,64,91,52,59,88,69,75}; for ( unsigned int i = 0; i < myGrades.size();i++){ std::cout <<...
Read More

C++ Array of Strings

There are a few different ways of creating a c++ Arrays of Strings #include <array>using namespace std;std::array<string,4> family = {"brother","sister","father","mom"} // std::array usage std::array<string,3> family = {"Me","You","Them"} #include <iostream> #include <array> using namespace std; int main(){ std::array<string,6> classmates = {"George",...
Read More

C++ Do While Syntax

Elements of a c++ do while loop do { statement(s); } while( condition ); #include <iostream> int main(){ int userCounter = 0,cnt=0; std::cout << "how many times should we loop ?\n"; std::cin >> userCounter; do { std::cout << "Counting to " << userCounter << " now in the loop for " << cnt + 1 << " times\n"; cnt++; }while( cnt < userCounter ); } So Line 13...
Read More

C++ Flow Control if else switch case syntax – steal our code

There are a number of flow control syntax constructs in C++. They are basically the same as those in C, so if you are a C programmer you can skip this section. The c++ flow control constructs involve variations of : if, if else if syntax, while(isTrue) ..., do ... while(isTrue) and my favorite ...c++ switch case syntax ...with variations of continue, break and default c++ Flow Control Code...
Read More
Top