#include <iostream> using namespace std; int main() { try { int a, b; cin >> a >> b; cout << a / b << endl; //try to divide by 0, you'll see error msg } catch(exception &e) { cout << "error happend: " << e.what() << endl; } }
Just like Python's for loop: #include <iostream> using namespace std; int main () { int v[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; for (auto x: v) cout << x << '\n'; }
#include <iostream> #include <list> #include <iterator> using namespace std; int max(list<int> a_list) { cout << "You gave me a list with a length of " << a_list.size() << "." << endl; a_list.sort(); a_list.reverse(); auto iterator = a_list.begin(); //create a iterator advance(iterator, 0); //give a 0 index, get the expected value in that list cout << *iterator << " is the biggest in this list." << endl; //from pointer address get int value return *iterator; } int main () { //std::list<int> mylist; //list included in std namespace. list<int> mylist={2, 3, 4, 1, 0}; //define a list contains int value max(mylist); //call max function return 0; }
Normally, you can get all commands by typing: docker See how many containers you got right now: docker ps -a example `docker run -it --publish 6606:80 --volume ${HOME}/Kivy-Chat:/Kivy-Chat --workdir /Kivy-Chat argensis/python3-kivy:nopip ls` `--publish 6606:80` container 80 part to host 6606 port `-volume ${HOME}/Kivy-Chat:/Kivy-Chat` forwarding Host `${HOME}/Kivy-Chat` to container `Kivy-Chat` `--workdir /Kivy-Chat` set container workdir to `Kivy-Chat` `argensis/python3-kivy:nopip` image name `ls` just command name, is also could be `python -c "print('hello, docker')"`