Загрузка данных


#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

class Str {
    char *s;
public:
    Str(const char *p) { s = new char[strlen(p) + 1]; strcpy(s, p); }
    ~Str() { delete[] s; }
    friend ostream& operator<<(ostream &out, const Str &str) { return out << str.s; }
    friend bool operator>(const Str &a, const Str &b) { return strlen(a.s) > strlen(b.s); }
};

int main(int argc, char *argv[]) {
    setlocale(LC_ALL, "Russian");
    Str s1("Привет"), s2("Программирование");

    cout << "s1 = " << s1 << "\ns2 = " << s2 << endl;
    cout << (s1 > s2 ? "s1 длиннее" : "s2 длиннее или равна") << endl;

    if (argc > 1) {
        ofstream fout(argv[1]);
        fout << "s1 = " << s1 << "\ns2 = " << s2 << endl;
        cout << "Записано в файл: " << argv[1] << endl;
    }
    return 0;
}