My First Week Learning C++

Study Journey

It's Friday, December 23rd and I finished the first chapter of the book C++ Primer. Chapter 1 was mainly a quick introduction to a lot of fundamentals of coding and C++ syntax. I liked it because even though I have an understanding of how simple coding language syntax works. I was able to quickly see how C++ syntax looks while refreshing on fundamental topics.

The chapter covers how to set up a simple c++ code, example: 
#include <iostream>

int main(){
    std::cout "Hello World" << std::endl;
}

This source is not from the book. But I created this code as an easy-to-explain bit of C++. So first off "#include <iostream>", this bit of code is sort of like a plugin. It tells the computer (compiler really) that you intend to use the "Input - Output Stream" library. The reason for inserting that plugin is to unlock the ability to use functions like :

"std::cout "Hello World" << std::endl;"

This particular function prints the message in quotes, and the function at the end creates a new line; so for example, if there was another message it would start on a new line under "Hello World".

Taking in Input

#include <iostream>
#include <string>
using namespace std;

int main(){
    std::cout << "Hello World, I'm David. What is your name?" 
              << std::endl;

    var name = "";
    std::cin >> name;

    std::cout << "Nice to meet you, " << name << std::endl;
}

This example has another library plugged in, I'm proud of this one because I didn't learn it from the book. I needed to use strings, so I looked up how to do it. and found this useful link: Stanford University - String

But let's stay on topic. To take data from the user of this program we must first create a storage bin so that we have somewhere to hold the user data. "var name" creates what's called a variable. A variable is one of the ways we can use to store the user data that we're about to receive. The Standford University Link above it shows another way but I'm leaving that for another time.

Right after we use the "cin" (character input) function which waits for the user to insert the data and then stores it inside the name variable. Then we post another message out to the user using the variable to confirm we now know the user name.


C++ Primer by Stanley B. Lippman, Josee Lajoie and Barbara E. Moo chapter 1 go into more topics like Flow of Control covering IF, For, and While Loops which is standard for all programming languages. And ends off with Classes and a quick preview as to how powerful it is. Highly recommend checking it out, next week I may cover the topics just mentioned in chapter 2. Till then!