그런즉 너희가 먹든지 마시든지 무엇을 하든지 다 하나님의 영광을 위하여 하라 (고전10:31)
NOTE: The following materials have been compiled and adapted from the numerous sources including my own. Please help me to keep this tutorial up-to-date by reporting any issues or questions. Send any comments or criticisms to idebtor@gmail.com Your assistances and comments will be appreciated.
Lecture notes by idebtor@gmail.com
To get started, do the first thing first:
- Read README.
- Read Syllabus.
- Read 'GettingStarted' - this file
- Follow instructions in 'GettingStarted' as soon as possible(ASAP).
These reading materials is available at my github.com/idebtor/nowic.
- View them always in github website automatically and better.
- GitHub does not support
LaTexyet. You may not see the well-formatted math equations.
- Install
Markdown Preview Plusextension in your browser(Chrome, Edge). - Go to
extensions, 도구 더보기 혹은 확장in the browser's setting - Locate
Markdown Preview Plusand click on theDETAILS 세부정보 - Check the option
Allow access to file URLs, 파일 URL에 대한 액세스 허용 - Drag and drop ~.md file in your brower.
- For
LaTex, check the math option inMarkdown Preview Plusicon in your brower top menubar'. - Enjoy nicely formatted HTML!
- Install
Markdown All in One&Auto-Open Previewextensions in yourCode. - Enjoy nicely formatted HTML!
Refer to my tutorial: https://youtu.be/sS1viPcXDIo
There are two ways to join Piazza, go the www.piazza.com.
-
To join Piazza, you may need the following information and
- School: Handong Global University
- Course: Data Structures and C++ for C Coders
-
If you have an email address that ends with ~.hgu.edu or ~.handong.edu domain and use it everyday, go the www.piazza.com and follow the instructions in the website.
-
On your request with your email address, I may register it for you. We'll be conducting all class-related discussion here this term. The quicker you begin asking questions on Piazza (rather than via emails), the quicker you'll benefit from the collective knowledge of your classmates and instructors. We encourage you to ask questions when you're struggling to understand a concept—you can even do so anonymously.
- For mac, it is really simple.
- Start a terminal and run the following command. Follow instructions if needed.
$ xcode-select --install - Check GCC installation with the following command. It has been installed successfully if you see some version numbers.
$ g++ -v
- To use g++ in Windows, we need to install two packages:
- MSYS2 (important note: install MSYS2 first)
- MinGW-w64
- Installing MSYS2 is relatively simple.
- Connect this website http://www.msys2.org/
- Select this msys2-x86_64-20190524.exe for 64 bit version.(the second button, usually)
- Download and install it while accept all the default setting.
- At the end, you will see a console opened when you accept all the default.
- If not, open a console
MSYS2console or runC:\msys64\msys2.exe.
- At the console, run the following command to update the package database and core system packages with: ($ in the command line below is a console prompt: don't type it.)
$ pacman -Syu
- If you see some failure messages during installation, run it a couple of times until you see a very long list of downloads. Even you may need to restart a console. To restart a console, run
C:\msys64\msys2.exe. - You may follow this good installation guide
- Open a console MSYS2 console and run the following command. Accept the default as they are. If some packages fail, run it again.
$ pacman -S mingw-w64-x86_64-gcc
-
The first one we want to add to the PATH is the path where
g++.exeexists. -
The second one is the path where some utility commands such as
ls,catandcpexist. -
By default, the paths are:
c:\msys64\mingw64\binc:\msys64\usr\bin
-
But it is a good idea to check and copy the folders instead of typing.
-
If you want to use it in
minttyorMSYS2/Mingw64consoles, add them to your.bash_profileas well.- Follow instructions in "UsingMintty.md" file stored in this folder.
- Start a console(
cmdorPowershellin Windows) or open aminttyconsole. - To check installation, run the following command:
$ g++ --version
-
You may see something like below:
$ g++ --version g++.exe (Rev2, Built by MSYS2 project) 9.2.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -
If you installed it in a different way, you may see .
$ g++ --version g++.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -
If you see something different from
x86_64-posix-seh-rev0orBuilt by MSYS2 project, you have chosen a wrong version. Go through the installation process with caution again.
MinGW-w64 installation Problem: ERROR res
- In some PC Windows, we have experienced a difficulty during MinGW-w64 installation.
- It fails with __`ERROR res`__ during the installation. I posted [this question](https://stackoverflow.com/questions/57894158/mingw-w64-installation-fails-with-error-res-in-windows-10) in the __stackoverflow__ and got [this answer](https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2/30071634#30071634). You may go their recommendation.
- In summary, you install __MSYS2__ first, and then install __MinGW-w64__ as part of __MSYS2__.
- __MSYS2__ installation is really easy and rarely fails.
- It comes with a command-line package manager (`pacman`).
- It offers always the newest `MinGW-w64/GCC` combo available.
- You can also install many other packages compatible with this toolchain.
- For details see [this answer](https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2/30071634#30071634).
- Don't forget adding the path `C:/mingw64/bin` to your __PATH__ environment variable.
This method fails when the user uses __KoreanUserName__. For MinGW-w64, follow this [good installation guide](https://brunch.co.kr/@mystoryg/56) available.
- __IMPORTANT NOTE__ During the installation, select the following option:
```
Architecture x86_64
```
__instead of__
```
Architecture xi686
```
- After installation, don't forget the installation path to `PATH` environment variable. In my case, the installation path was:
```
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
```
- To use Mintty or MSYS2 console, follow instructions in "UsingMintty.md" file stored in this folder.
- Install git from this site for your computer.
- Install GitHub Desktop
After installation of GitHub Desktop, be a member if already not.
-
Clone the GitHub
nowicrepository into your local computer: -
How to clone a repository from GitHub: Refer to this site.
-
Click 'watch' and 'star' at the top of the web page.
-
Then, in your computer, you may have the following github/nowic folder as shown below:
C:\GitHub\nowic -
Since this
nowicrepository can be updated anytime, keep this local repository as "read-only". Don't code yours here!. -
Copy them into your own repository or your own local development folders in your computer you can easily access them. They should look like the following:
~/nowic/include # include files ~/nowic/labs # labs ~/nowic/lib # nowic.lib, libnowic.a, libnowic_mac.a ~/nowic/src # source files ~/nowic/psets # problem sets - homework ~/nowic/tools # about tools - Code, GCC, Git, GitHub, Visual Stuido etc.- For example: The pset1(problem set 1) folder provides you with a few files for your first homework assignment.
~/pset1/pset1.pdf # this file ~/pset1/hellox.exe # a solution to compare your work ~/pset1/names.txt # a list of names used in Step 5.Note for Multi-screen users: Remove the following file if GitHub Desktop is displayed off-screen. Restart Desktop GitHub. (
userbelow may be different in your system.)C:\Users\user\AppData\Roaming\GitHub Desktop\window-state.jsonJoyNote: How do I force
git pullto overwrite local files?- Go to the ~/nowic folder.
- Open a console and run the following two commands.
git fetch --all git reset --hard origin/masteror
git stashExplanation:
git fetchdownloads the latest from remote without trying to merge or rebase anything. Then thegit resetresets the master branch to what you just fetched. The--hardoption changes all the files in your working tree to match the files in origin/master Caution: If you have any local changes, they will be lost. With or without --hard option, any local commits that haven't been pushed will be lost.JoyNote: How do I keep my local files clean after trials?
- Go to the ~/nowic folder.
- Open a console and run the following command.
git clean -fExplanation: To delete all untracked files.
- Open a console. (may use cmd or powershell)
- You may use cmd or powershell at this point. Sooner or later, however, we are going to use a different kind of console called mintty. You may read UsingMinttyInMinGW.md for the Mintty installation at
nowicfolder.
- You may use cmd or powershell at this point. Sooner or later, however, we are going to use a different kind of console called mintty. You may read UsingMinttyInMinGW.md for the Mintty installation at
- Open hello.cpp file with Code
Code hello.cpp - Build an executable. The output name depends on your OS: hello.exe, a.exe for windows; hello.out, a.out for linux and macOS. Mac users may need to add -std=c++11 option to compile as shown below:
g++ hello.cpp -o hello # hello.exe g++ -std=c++11 hello.cpp -o hello # hello.out for macOS g++ hello.cpp # a.exe or a - Run the executable.
./hello # PowerShell ./a # PowerShell hello # Cmd, Linux, macOS a # Cmd, Linux, macOS
It is a tradition to write a Hello World! program when you learn a new programming language. The following program prints Hello World! on a console. Create a file with the following contents. Its file name is hello.cpp
// file: hello.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
}
//The line begins with two slashes is not a part of source code. This line will be excluded when the program runs.#includeThe line begins with#is called apreprocessor directive. The preprocessor reads your program before it is compiled and only executes those lines beginning with a # symbol. When you send the file to the compiler, the preprocessor substitutes the#includewith the contents of the specified file.<iostream>Theiostreamfile must be included since this program usescoutto display console output. This kind of file is called a header file. In this way you can create and use modules that define functions that you only add to your code when you need them. There are lots of different header files available for many different purposes.using namespace std;C++ uses namespaces to organize the names of program entities. This line declares that the program will be accessing entities whose names are part of the namespace calledstd. Every name created by theiostreamfile is part ofstdnamespace. In order for a program to use the entities such ascoutiniostream, it must have access to thestdnamespace. You may rewrite hello.cpp as shown below:
// file: hello.cpp
#include <iostream>
int main() {
std::cout << "Hello World!";
}
Observe two versions Hello World! program to see the difference. The difference is whether you are using the namespace or not.
To run the program, you must make an executable from the source code file, hello.cpp. We use the compiler to generate an executable (or runnable) file from the code in the source file. The executable file ends with .exe or .out extension, or without it as our source file ends with .cpp extension. We might compile the file as follows:
- On the console, type the following line (without $) and press
Enterkey. - Mac users may need to add -std=c++11 option to compile as shown below:
$ g++ hello.cpp # generates a.exe, a
$ g++ -std=c++11 hello.cpp # for macOS
$ ./a.exe # runs a.exe for PowerShell
$ ./a # runs a.exe or a for PowerShell and macOS
$ a # for Cmd Windows
- The line above compiles (and links) the source code and generates an executable called
a.exeora. $is a console prompt. (You don't need to enter it.)- The line above compiles (and links) the source code and generates an executable called
a.exe g++is the name of our compiler, and#begins a command-line comment. We can run the executable file,a.exeora, which will run our main function. If you want to name the executable, you may provide the file name with-.ooption as follows:
$ g++ hello.cpp -o hello # generates hello.exe
$ ./hello.exe # runs hello.exe
$ ./hello # runs hello.exe, hello for macOS & PS
$ hello # for Cmd Windows
JoyNote:
- Run
hello.exeorhellowithout./in front, when you run it at Linux, macOS and mintty console^^.
For further study of C or C++ basics, the following two video lectures in YouTube are recommended. A solid background in C will do good for C++ study in this course.
- Beginning C Programming by Bluefever
- C++ Programming in One Video by Derek Banas
- C++ Tutorial by Derek Banas
- Watch Derek's lecture or more.
- Read ArgcArgv.md. It may help you do the first problem set(pset).
- Read UsingMintty.md at
nowicand installMinttyconsole.
One thing I know, I was blind but now I see. John 9:25
