could anyone tell me or point me to a simple example of how to append an int to a stringstream containing the word "Something" (or any word)?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- how to split a list into a given number of sub-lis
- thread_local variables initialization
相关文章
- JSP String formatting Truncate
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
I'd probably do something on this general order:
With a normal stream, to add to the end, you'd open with
std::ios::ate
orstd::ios::app
as the second parameter, but with string streams, that doesn't seem to work dependably (at least with real compilers -- neither gcc nor VC++ produces the output I'd expect when/if I do so).For future reference, check this out.
http://www.cplusplus.com/reference/iostream/stringstream/
If you are already using boost, it has lexical_cast that can be be used for this. It is basically a packaged version of the above, that works on any type that can be written to and read from a stream.
Its probably not worth using if you aren't using boost already, but if you are it can make your code clearer, especially doing something like