Output stream class to operate on strings.
Questions tagged [ostringstream]
150 questions
0
votes
2 answers
C++ Error C2440
I am trying to create a random number generator in C++, which puts the result in a textBox.
I get the error 'error C2440: 'initializing' : cannot convert from 'std::basic_string<_Elem,_Traits,_Ax>' to 'System::String ^
My code is:
int rnd = 1 +…

Joe
- 104
- 1
- 13
0
votes
1 answer
How to insert in middle of stringstream during serialisation?
std::ostringstream oss;
boost::archive::text_oarchive oa(oss);
I add variable number of content to this oa, like this
oa & int1;
oa &int2;
--------------------> insert number of matrices here
oa & matrix1;
..//do some processing
…
user494461
0
votes
5 answers
Why is ostringstream not emptying?
I'm trying to convert an int to a string via an ostringstream but every time I put data into the stream, it stays in the stream. I've tried using both .flush() and <

Daniel
- 2,435
- 5
- 26
- 40
0
votes
2 answers
Dynamic output filenames (C++)
I'm trying to create output files subscripted by a dynamic index ( d = {0,...,NUM_DEMES-1}). Currently, I'm only getting output files for the first value (d=0).
#include
#include
void Simulation::updateSimulation( double t )
{
…

Sarah
- 1,614
- 1
- 23
- 37
0
votes
1 answer
ostringstream::write method modifies input parameter
Consider the following snippet which gets some binary data and writes it to an ostringstream object:
unsigned char* payload;
unsigned long size;
GetData(&payload, &size);
std::cout << md5(payload, size) << std::endl;
std::ostringstream…

incrediblehulk
- 409
- 2
- 11
0
votes
1 answer
Is there a standard formatting function or operator that will round up? (or down?)
I am using ostringstream to output a number to 2 decimal places as follows
std::ostringstream ostr;
ostr << std::fixed << std::setprecision(2);
ostr << cylinderLength;
So, if cylinderLength = 0.594, the above outputs 0.59 as expected.
Is there an…
user236520
0
votes
6 answers
Need a macro to create a std::string from a std::ostringstream and a << arg list
I want to write a macro that takes as its only argument a list of std::ostream& operator<< concatenated objects and passes the consolidated string as a single std::string object to a function. The ability to pass the consolidated string to a…

phonetagger
- 7,701
- 3
- 31
- 55
0
votes
1 answer
ostringstream SOMETIMES causes a crash
So I wrote an implementation of an ArrayList over the summer, and I have a toString method within which I use an ostringstream object to tack on strings and then output them.
the method is below:
template
std::string…

Ethan
- 1,206
- 3
- 21
- 39
0
votes
1 answer
Why does deleting a ostringstream object as in my code leads to segmentation fault?
#include
#include
#include
#include
#include
using namespace std;
int main()
{
ostringstream out;
ostringstream tmpstr;
tmpstr << "ritesh is here";
out << tmpstr.str().c_str();
…

Invictus
- 4,028
- 10
- 50
- 80
-1
votes
2 answers
How can I fix this error? "Method 'str' could not be resolved"
What is the meaning of this problem and how can I fix it?
It's look like it's not meet the function str() while I try to use it.
In fact, I want to take the "string" from rhs and to put it in this->file, so if you have alternative idea, it's good…

AskMath
- 415
- 1
- 4
- 11
-1
votes
1 answer
How to turn off scientific notation for double when appending it to ostringstream?
I have a small function which converts double to std::string:
std::string convertDoubleToString( double value ) {
std::ostringstream ostr;
ostr << value;
return ostr.str();
}
I don't want to use the scientific notation here. How can I…

JavaRunner
- 2,455
- 5
- 38
- 52
-1
votes
1 answer
How can I copy an ostringstream object into another one (using gcc-4.7.0)
All the other posts tell me to change my compiler, but I can't since I'm supposed to be working with this compiler. Please help!
void foo(ostringstream &os) {
ostringstream temp;
temp << 0;
//do something
os.swap(temp);
}
^I can'…

soochism
- 13
- 1
- 5
-3
votes
1 answer
g++: crash when accessing ostringstream::str().c_str()
The code below fails on gcc 9.4.0. Is this just a bug, or have I done something stupid?
log declares an ostringstream object, writes a filename and a line number to it, and attempts to do something with the object's underlying…

QF0
- 329
- 2
- 14
-3
votes
1 answer
potential issue in this code using osstreamstring
Is there any issue in the following code? I am told it's there, but I couldn't find it...
std::string fun(int i)
{
std::ostringstream t;
t<<"My int is "<

George Nel
- 1
- 1
-5
votes
1 answer
No matching function call for ostringstream `.str()`
I have a function which is defined as
void writeSite(string& site, const string& contentType);
Now I am building my string with the std::ostringstream function.
After finishing the string I want to call the writeSite function. But I get the…

Pascal
- 2,175
- 4
- 39
- 57