Output stream class to operate on strings.
Questions tagged [ostringstream]
150 questions
1
vote
1 answer
ostringstream is an undefined type?
In my C++ project I'm trying to do this:
std::ostringstream stream(std::ostringstream::out);
But I'm getting an error:
error C2027: use of undefined type 'std::basic_ostringstream<_Elem,_Traits,_Alloc>'
I'm already including iostream and ostream…

meds
- 21,699
- 37
- 163
- 314
1
vote
1 answer
Why is locale causing std::ostringstream to get slower as I use more threads?
I'm building some formatted strings using std::ostringstream. When running on a single thread, code profiling shows no bottle neck caused by std::ostringstream.
When I start using more threads, std::ostringstream slows down due to…

user1139069
- 1,505
- 2
- 15
- 27
1
vote
0 answers
why stringsteam.str().c_str() is not giving expected results?
I don't know how to ask this question as this looks very trivial, but surprisingly it's not working in my project in the visual studio. It works in the sample program. Does any optimization flag are the reason behind this?
std::ostringstream s;
…

novice
- 179
- 1
- 5
- 15
1
vote
3 answers
Problem with ostringstream and copy constructor
Possible Duplicates:
Why copying stringstream is not allowed?
how copy from one stringstream object to another in C++?
Compiling class T fails with Visual C++ and GCC producing iostreams template errors. Here is the code:
#include…

Paul Jurczak
- 7,008
- 3
- 47
- 72
1
vote
2 answers
reading/writing from ostringstream changes original data
Inside a test, I write a given value to an ostringstream. After that, I try to evaluate if the correct value was written. However, it seems that the original value I wrote into the stream is changed later on while reading from it.
I reduced my…

alex
- 310
- 1
- 6
1
vote
0 answers
Valgrind error when converting ostringstream to a string
I have the following (simplified) code:
class py_string {
PyObject* v;
public:
py_string(const std::string& str) {
// See https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_FromStringAndSize
// The string data is…

Pasha
- 6,298
- 2
- 22
- 34
1
vote
2 answers
how to convert an ostringstream hex string character pairs to a single unit8_t equivalent binary value
I am trying to do the following:
I have an assembled ostringstream object that contains a hex payload to be transmitted. Say, it might be
03125412349876543210af (this is representing the data using hex convention in my string)
This string is…

Spangas
- 15
- 2
1
vote
2 answers
Convert std::ostringstream into std::stringstream
The next code returns an empty string in ss:
#include
#include
#include
int main () {
std::ostringstream oss;
oss << "Text";
std::stringstream ss;
ss.basic_ios::rdbuf(oss.rdbuf());
…

Medical physicist
- 2,510
- 4
- 34
- 51
1
vote
0 answers
Why is GStreamer playback suffering when using an APK from a Xamarin Android application?
I'm trying to get a sample application provided by the media streaming framework Gstreamer to work as a Xamarin Android application. The application plays and displays an RTSP stream. To do so, I took the sample Android application (Java-based, with…

Ben
- 314
- 2
- 11
1
vote
0 answers
How to get the IBM cplex stdout into a string instead of printing on console?
I am using IBX cplex solver in my C++ program. by default, it prints the solve output into console. But, i wanted this solver output as a string, which can later be used for logging or cout. To achieve this, i used the below code snippet (with…

Karthick
- 357
- 4
- 13
1
vote
1 answer
Why is my copy constructor deleted?
Given the following code:
#include
#include
#include
#include
#include
using std::string;
using std::ostream;
using std::cout;
using std::endl;
typedef std::basic_ostringstream…

Software_t
- 576
- 1
- 4
- 13
1
vote
1 answer
Inline ostringstream macro reloaded
Referring to C++ format macro / inline ostringstream
The question there was for a macro that allows inline concatenation of objects to create a string, iostream-style.
The answer was:
#define SSTR( x ) dynamic_cast< std::ostringstream & >( \
…

DevSolar
- 67,862
- 21
- 134
- 209
1
vote
1 answer
How to pass custom allocator to std::basic_ostringstream in C++11?
I want to use a custom allocator to allocate memory from a freelist for std::basic_ostringstream. Here is my custom allocator which I want to use:
template
struct NAlloc {
typedef Tp value_type;
typedef value_type*…

user3059007
- 81
- 9
1
vote
0 answers
String append vs Ostringstream
I checked the performance comparison for the below two programs in c++. One program loading strings into a string by string concatenation. Another one loading strings into a ostringstream buffer.
By String:
string mytext =…

Smith Dwayne
- 2,675
- 8
- 46
- 75
1
vote
2 answers
Why is my std::string obtained via stream being overwritten?
Assume I have a function like so:
std::string get_shader(std::string path) {
std::string fullpath = "./resources/shaders/" + path;
std::ifstream vertexShaderFile(fullpath);
std::ostringstream vertexBuffer;
vertexBuffer <<…

Bjorn
- 69,215
- 39
- 136
- 164