J
Jerry Coffin
[ ... ]
I'm sure you could if you tried.
int add(int i, int j) {
std:fstream x("somename", std::ios::binary);
std::string a(i, ' ');
std::string b(j, ' ');
x << a;
x << b;
x.seekp(i, std::ios::begin);
x.seekp(j, std::ios::cur);
return x.tellp();
}
Much like your string-based solution, there's little room for question
that this is just hiding the arithmetic, not really avoiding it. The
gyrations with seekp even add a bit of flexibility: this works when j is
negative, as long as its magnitude is smaller than i's.
(I might add that I can't think of
a more inefficient way of adding two numbers.)
I'm sure you could if you tried.
int add(int i, int j) {
std:fstream x("somename", std::ios::binary);
std::string a(i, ' ');
std::string b(j, ' ');
x << a;
x << b;
x.seekp(i, std::ios::begin);
x.seekp(j, std::ios::cur);
return x.tellp();
}
Much like your string-based solution, there's little room for question
that this is just hiding the arithmetic, not really avoiding it. The
gyrations with seekp even add a bit of flexibility: this works when j is
negative, as long as its magnitude is smaller than i's.