sum of two integers

J

Jerry Coffin

[ ... ]

(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::eek: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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,648
Latest member
NREEugene

Latest Threads

Top