---------------
#include<string>
#include<list>
---------------
std::string s {"Cztery nogi dobrze, dwie nogi le!"};
std::list<std::string> slogans {"Wojna to pokj", "Wolno to niewola", "Ignorancja to sia"};
---------------
#include<string>     // umoliwienie dostpu do standardowych narzdzi acuchowych
using namespace std; // umoliwienie dostpu do zawartoci przestrzeni nazw std bez przedrostka std::
string s {"C++ is a general-purpose programming language"}; // OK: string to dokadniej std::string
---------------
string compose(const string& name, const string& domain)
{
    return name + '@' + domain;
}
auto addr = compose("dmr","bell-labs.com");
---------------
void m2(string& s1, string& s2)
{
    s1 = s1 + '\n'; // dodanie znaku nowego wiersza
    s2 += '\n';     // dodanie znaku nowego wiersza
}
---------------
string name = "Niels Stroustrup";

void m3()
{
    string s = name.substr(6,10);  // s = "Stroustrup"
    name .replace(0,5,"nicholas"); // teraz acuch to "nicholas Stroustrup"
    name[0] = toupper(name[0]);    // teraz acuch to "Nicholas Stroustrup"
}
---------------
string incantation;

void respond(const string& answer)
{
    if (answer == incantation) {
        // czary mary
    }
    else if (answer == "tak") {
        //...
    }
    //...
}
---------------
void f()
{
    cout << 10;
}
---------------
void g()
{
    int i {10};
    cout << i;
}
---------------
void h(int i)
{
    cout << "Warto i wynosi ";
    cout << i;
    cout << '\n';
}
---------------
Warto i wynosi 10
---------------
void h2(int i)
{
    cout << "Warto i wynosi " << i << '\n';
}
---------------
void k()
{
    int b = 'b'; // uwaga: char niejawnie przekonwertowany na int
    char c = 'c';
    cout << 'a' << b << c;
}
---------------
void f()
{
    int i;
    cin >> i; // wczytuje liczb typu int do i

    double d;
    cin >> d; // wczytuje liczb typu double do d
}
---------------
void hello()
{
    cout << "Napisz, jak si nazywasz\n";
    string str;
    cin >> str;
    cout << "Cze, " << str << "!\n";
}
---------------
Cze, Stefan!
---------------
Cze, Stefan!
---------------
void hello_line()
{
    cout << "Napisz, jak si nazywasz\n";
    string str;
    getline(cin,str);
    cout << "Cze, " << str << "!\n";
}
---------------
Cze, Stefan Batory
---------------
struct Entry {
    string name;
    int number;
};
---------------
ostream& operator<<(ostream& os, const Entry& e)
{
    return os << "{\"" << e.name << "\", " << e.number << "}";
}
---------------
istream& operator>>(istream& is, Entry& e)
    // wczytuje par { "nazwisko" , numer }. Uwaga: formatowanie przy uyciu { " "  i }
{
    char c, c2;
    if (is>>c && c=='{' && is>>c2 && c2=='"') { // czy na pocztku jest {"
        string name;                // domylna warto acucha to pusty acuch: ""
        while (is.get(c) && c!='"') // wszystko przed " jest czci nazwiska
            name+=c;

        if (is>>c && c==',') {
            int number = 0;
            if (is>>number>>c && c=='}') { // wczytuje numer i }
                e = {name ,number};        // przypisanie do pozycji
                return is;
            }
        }
    }
    is.setf(ios_base::failbit); // rejestracja niepowodzenia w strumieniu
    return is;
}
---------------
{ "John Marwood Cleese" , 123456 }
{"Michael Edward Palin",987654}
---------------
for (Entry ee; cin>>ee; ) // wczytanie z cin do ee
    cout << ee << '\n';   // wydruk ee w cout
---------------
{"John Marwood Cleese", 123456}
{"Michael Edward Palin", 987654}
---------------
vector<Entry> phone_book = {
    {"David Hume",123456},
    {"Karl Popper",234567},
    {"Bertrand Arthur William Russell",345678}
};
---------------
void print_book(const vector<Entry>& book)
{
    for (int i = 0; i!=book.size(); ++i)
        cout << book[i] << '\n';
}
---------------
void print_book(const vector<Entry>& book)
{
    for (const auto& x : book)  // opis auto: 2.2.2
        cout << x << '\n';
}
---------------
vector<int> v1 = {1, 2, 3, 4}; // rozmiar 4
vector<string> v2;             // rozmiar 0
vector<Shape*> v3(23);         // rozmiar 23; pocztkowa warto elementw: nullptr
vector<double> v4(32,9.9);     // rozmiar 32; pocztkowa warto elementw: 9.9
---------------
void input()
{
    for (Entry e; cin>>e;)
        phone_book.push_back(e);
}
---------------
vector<Entry> book2 = phone_book;
---------------
void silly(vector<Entr y>& book)
{
    int i = book[book.size()].number; // book.size() jest poza zakresem
    //...
}
---------------
template<typename T>
class Vec : public std::vector<T> {
public:
    using vector<T>::vector; // uycie konstruktorw z typu vector (pod nazw Vec); patrz: 20.3.5.1

    T& operator[](int i)     // sprawdzanie zakresu
        { return vector<T>::at(i); }

    const T& operator[](int i) const // sprawdzanie zakresu obiektw const; 3.2.1.1
        { return vector<T>::at(i); }
};
---------------
void checked(Vec<Entry>& book)
{
    try{
        book[book.size()] = {"Jan",999999}; // spowoduje wyjtek
        //...
}
    catch (out_of_range) {
        cout << "Bd zakresu\n";
    }
}
---------------
int main()
try{
    // kod programu
}
catch (out_of_range) {
    cerr << "Bd zakresu\n";
}
catch (...) {
    cerr << "Wystpi nieznany wyjtek\n";
}
---------------
list<Entry> phone_book = {
    {"David Hume",123456},
    {"Karl Popper",234567},
    {"Bertrand Arthur William Russell",345678}
};
---------------
int get_number(const string& s)
{
    for (const auto& x : phone_book)
        if (x.name==s)
            return x.number;
    return 0; // 0 reprezentuje "nie znaleziono numeru"
}
---------------
int get_number(const string& s)
{
    for (auto p = phone_book.begin(); p!=phone_book.end(); ++p)
        if (p->name==s)
            return p->number;
    return 0; // 0 reprezentuje "nie znaleziono numeru"
}
---------------
void f(const Entry& ee, list<Entry>::iterator p, list<Entry>::iterator q)
{
    phone_book.insert(p,ee); // dodaje ee przed elementem wskazywanym przez p
    phone_book.erase(q);     // usuwa element wskazywany przez q
}
---------------
map<string,int> phone_book {
    {"David Hume",123456},
    {"Karl Popper",234567},
    {"Bertrand Arthur William Russell",345678}
};
---------------
int get_number(const string& s)
{
    return phone_book[s];
}
---------------
unordered_map<string,int> phone_book {
    {"David Hume",123456},
    {"Karl Popper",234567},
    {"Bertrand Arthur William Russell",345678}
};
---------------
int get_number(const string& s)
{
    return phone_book[s];
}
---------------
bool operator<(const Entry& x, const Entry& y) // mniej ni
{
    return x.name<y.name; // porzdkuje pozycje wg nazwisk
}
void f(vector<Entry>& vec, list<Entry>& lst)
{
    sort(vec.begin(),vec.end());                    // uycie operatora < do porzdkowania
    unique_copy(vec.begin(),vec.end(),lst.begin()); // nie kopiuj kolejnych identycznych elementw
}
---------------
list<Entry> f(vector<Entry>& vec)
{
    list<Entry> res;
    sort(vec.begin(),vec.end());
    unique_copy(vec.begin(),vec.end(),back_inserter(res)); // dodaje na kocu res
    return res;
}
---------------
bool has_c(const string& s, char c) // czy s zawiera znak c?
{
    auto p = find(s.begin(),s.end(),c);
    if (p!=s.end())
        return true;
    else
        return false;
}
---------------
bool has_c(const string& s, char c) // czy s zawiera znak c?
{
    return find(s.begin(),s.end(),c)!=s.end();
}
---------------
vector<string::iterator> find_all(string& s, char c) // znajduje wszystkie wystpienia c w s
{
    vector<string::iterator> res;
    for (auto p = s.begin(); p!=s.end(); ++p)
        if (*p==c)
            res.push_back(p);
    return res;
}
---------------
void test()
{
    string m {"Mary had a little lamb"};
    for (auto p : find_all(m,'a'))
        if (*p!='a')
            cerr << "Bd!\n";
}
---------------
template<typename C, typename V>
vector<typename C::iterator> find_all(C& c, V v) // znajduje wszystkie wystpienia v w c
{
    vector<typename C::iterator> res;
    for (auto p = c.begin(); p!=c.end(); ++p)
        if (*p==v)
            res.push_back(p);
    return res;
}
---------------
template<typename T>
using Iterator<T> = typename T::iterator;

template<typename C, typename V>
vector<Iterator<C>> find_all(C& c, V v) // znajduje wszystkie wystpienia v w c
{
    vector<Iterator<C>> res;
    for (auto p = c.begin(); p!=c.end(); ++p)
        if (*p==v)
            res.push_back(p);
    return res;
}
---------------
void test()
{
    string m {"Mary had a little lamb"};
    for (auto p : find_all(m,'a')) // p jest string::iterator
        if (*p!='a')
            cerr << "Bd acucha!\n";

    list<double> ld {1.1, 2.2, 3.3, 1.1};
    for (auto p : find_all(ld,1.1))
        if (*p!=1.1)
            cerr << "Bd listy!\n";

    vector<string> vs { "red", "blue", "green", "green", "orange", "green" };
    for (auto p : find_all(vs,"green"))
        if (*p!="green")
            cerr << "Bd wektora!\n";

    for (auto p : find_all(vs,"green"))
        *p = "vert";
}
---------------
ostream_iterator<string> oo {cout}; // wysya acuchy do cout
---------------
int main()
{
    *oo = "Witaj, ";    // znaczy cout<<"Witaj, "
    ++oo;
    *oo = "wiecie!\n"; // znaczy cout<<"wiecie!\n"
}
---------------
istream_iterator<string> ii {cin};
---------------
istream_iterator<string> eos {};
---------------
int main()
{
    string from, to;
    cin >> from >> to;                     // pobranie nazw plikw rdowego i docelowego

    ifstream is {from};                    // strumie wejciowy dla pliku rdowego
    istream_iterator<string> ii {is};      // iterator wejciowy dla strumienia
    istream_iterator<string> eos {};       // stranik wejcia

    ofstream os{to};                       // strumie wyjciowy dla pliku docelowego
    ostream_iterator<string> oo {os,"\n"}; // iterator wyjciowy dla strumienia

    vector<string> b {ii,eos};             // b jest wektorem zainicjowanym z wejcia [ii:eos)
    sort(b.begin(),b.end());               // sortuje bufor

    unique_copy(b.begin(),b.end(),oo);     // kopiowanie bufora do wyjcia i usunicie duplikatw

    return !is.eof() || !os;               // zwrot bdu (2.2.1, 38.3)
}
---------------
set<string> b {ii,eos};     // pobiera acuchy z wejcia
copy(b.begin(),b.end(),oo); // kopiuje bufor na wyjcie
---------------
int main()
{
    string from, to;
    cin >> from >> to;  // pobranie nazw plikw rdowego i docelowego

    ifstream is {from}; // strumie wejciowy dla pliku rdowego
    ofstream os {to};   // strumie wyjciowy dla pliku docelowego

    set<string> b {istream_iterator<string>{is},istream_iterator<string>{}}; // wczytywanie danych
    copy(b.begin(),b.end(),ostream_iterator<string>{os,"\n"});              // kopiowanie na wyjcie

    return !is.eof() || !os; // zwrot bdu (2.2.1, 38.3)
}
---------------
void f(map<string,int>& m)
{
    auto p = find_if(m.begin(),m.end(),Greater_than{42});
    //...
}
---------------
struct Greater_than {
    int val;
    Greater_than(int v) : val{v} { }
    bool operator()(const pair<string,int>& r) { return r.second>val; }
};
---------------
int cxx = count_if(m.begin(), m.end(), [](const pair<string,int>& r) { return 
(r.second>42; });
---------------
sort(v.begin(),v.end());
---------------
namespace Estd {
    using namespace std;

    template<class C>
    void sort(C& c)
    {
        sort(c.begin(),c.end());
    }

    template<class C, class Pred>
    void sort(C& c, Pred p)
    {
        sort(c.begin(),c.end(),p);
    }
    //...
}