Question: Currently I have a scenario where I want to check whether writing a given string to a filestream will grow the file beyond a given size (this is used for logfile rotation). Now, `std::ofstream::tellp()` returns a `streampos`, but `std::string::size()` returns a `size_t`. The effect is, that this does not work:

```
out_stream.tellp() + string.size() < limit

```

because apparently there is an ambiguous overload of `operator +` for these types. This leads me to two questions:

1. How can I resolve the above ambiguity?
2. How do all the different types (`size_t`, `streamsize`, `streampos`, `streamoff`) relate to each other? When can they be safely converted, and what are possible pitfalls. I am generally confused about these types. All I know is that they are implementation dependent, and that they make certain guarantees (e.g. `size_t` is always large enough to hold the size of the larges object that would fit into memory on the architecture for which the application was compiled), but what are the guarantees concerning interoperability of these types (see example above, or comparing a `streamsize` to a `size_t`)?

Answer: 
I believe the standard says that `streamsize` is implementation-specific, so no help there. For a practical answer, you can check the headers where these are `typedef`ed.

Considering that `size_t` might be 4 bytes while your application *could* conceivably operate on a stream of more than 4GB length, I believe that you should cast to a known-good-size type for interoperating for an airtight solution.

Of course, if you know (maybe with a compile-time assertion) that `size_t` or `streamsize` is 8 bytes long, you can use that type directly. If you have a stream whose length doesn't fit in 8 bytes, you have more serious problems than casting to the right type.
If you have big sizes, isn't **unsigned long long** the best you can get. If that isn't big enough, what else is?