#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);
friend bool operator>(const Str &a, const Str &b);
};
ostream& operator<<(ostream &out, const Str &str)
{
out << str.s;
return out;
}
bool operator>(const Str &a, const Str &b)
{
return strlen(a.s) > strlen(b.s);
}
int main(int argc, char *argv[])
{
Str s1("Hello");
Str s2("Programming");
cout << "s1 = " << s1 << endl;
cout << "s2 = " << s2 << endl;
if (s1 > s2)
cout << "s1 dlinnee s2" << endl;
else
cout << "s2 dlinnee ili ravno s1" << endl;
if (argc > 1)
{
ofstream fout(argv[1]);
if (fout.is_open())
{
fout << "s1 = " << s1 << endl;
fout << "s2 = " << s2 << endl;
fout.close();
cout << "Dannye zapisany v fail: " << argv[1] << endl;
}
else
cout << "Ne udalos otkryt fail" << endl;
}
else
cout << "Imya faila ne peredano v komandnoy stroke" << endl;
return 0;
}