Output stream class to operate on strings.
Questions tagged [ostringstream]
150 questions
0
votes
0 answers
Why local variable of type "ostringstream" is getting error messages for things that should be valid
Here is my code:
% cat ch.cpp
using namespace std;
#include
#include
#include
typedef const char* cstring;
class GameCharacter
{
private:
string desc;
string name;
string chid;
public:
…

A. P. Damien
- 376
- 2
- 10
0
votes
1 answer
ostringstream to print float numbers in fixed notation avoiding scentific notation
I'm using the following code to print float number (value is of type float):
std::ostringstream ss;
ss << std::fixed << std::setprecision(9) << value;
which works fine most the cases. However, when value is very small I'm getting things…

fgalan
- 11,732
- 9
- 46
- 89
0
votes
1 answer
ostringstream gets wrong int value after incrementation [c++]
This is part of my code:
for(int i=0; i<10; i++)
{
tab[i]=new char[80];
oss.str("");
oss<<"line number: <

Karol Borkowski
- 532
- 7
- 19
0
votes
2 answers
print vector of objects within an object
I'm trying to print an object Order (actually a vector of Orders). Order has some data members, including a vector with other objects, Purchase.
I can print the vector to cout on its own, and I can print vector if I ignore the…

JEB
- 5
- 1
0
votes
1 answer
C++ STL in VS2008: std::ostringstream throws std::bad_alloc after heavy assign/clear usage
I have come across a situation (on Win32) where the std::ostringstream object continues to consume process memory, even when it is ostensibly cleared out after a series of append-type operations. Please take a look at this C++ fragment:
int…
0
votes
2 answers
stringstream or ostringstream for writing in file?
To write data from ostringstream to a ofstream, I have to write something like this:
std::ostringstream ss;
myFile<

Silencer
- 1,602
- 4
- 17
- 27
0
votes
5 answers
What's the fastest way in C++ to concat a list of variables in different types to a comma separated string?
string A = "test";
double B = 123.45;
float C = 43.23;
char D = 'c';
Trying to join them to product a string string res = "test,123.45,43.23,c". What is the fastest way?
ostringstream is good, but seems not fast enough.

lichgo
- 523
- 1
- 6
- 16
0
votes
1 answer
Want ostringstream to modify passed string
I would like std::ostringstream to modify the string I pass it:
#include
#include
#include
void My_Function(std::string& error_message)
{
std::ostringstream error_stream(error_message);
// For Nipun Talukdar:
/*…

Thomas Matthews
- 56,849
- 17
- 98
- 154
0
votes
2 answers
reading space separated data and pushing it into proper contaner
I am facing a problem how to read space separated data from input stream.
Lets say we need to input J 123 7 3 M. First is letter and last is letter. The rest is int.
vector ints;
vector chars;
stringstream ss;
...
cin >>…

Tukkan
- 1,574
- 2
- 18
- 33
0
votes
4 answers
String replacement in C++ on string of arbitrary length
I have a string I get from ostringstream. I'm currently trying to replace some characters in this string (content.replace(content.begin(), content.end(), "\n", "");) but sometimes I get an exception:
malloc: *** mach_vm_map(size=4294955008) failed…

ruipacheco
- 15,025
- 19
- 82
- 138
0
votes
1 answer
Odd behavior with doubles and oStringStream
so I am working on an expression evaluator as an internal component on a work related project. but I am having some weird behavior when it comes to the output of floating point math...
the evaluator takes in a string
e.evaluate("99989.3 +…

asuppa
- 571
- 1
- 11
- 27
0
votes
1 answer
Strange behaviour with std::unique_ptr and std::ostringstream (SIGSEGV)
I am currently trying to wrap an std::ostringstream into and std::unique_ptr.
My current code compiles, but at runtime, I am getting an segmentation fault.
When I do not wrap it - using an old c-style pointer, it runs fine.
For a more detailed…

Sebastian Büttner
- 351
- 3
- 13
0
votes
1 answer
Error C2280 trying to convert int to string using osstream
I am just trying to output an integer variable using DrawText();
Here is the error:
Error 7 error C2280:
'std::basic_ostringstream,std::allocator>::basic_ostringstream(const
std::basic_ostringstream,std::allocator>
&)' : attempting to…

Nicolas Maltais
- 15
- 5
0
votes
2 answers
Passing references through a function?
I need to take some code within a function and put that within yet another function. The only problem is the variables are now out a scope. Whenever I try to pass them both as references I can hit with an onslaught of errors.
The relevant part of my…
0
votes
2 answers
Why is this returning an address in the console?
I'm trying to wrap my head around ostringstreams and istringstreams. So, as I always do, I made a log-in program out of it. but every time I try to cout the contents of the username and password variables, it returns the address!
Purpose for…