Questions tagged [ostringstream]

Output stream class to operate on strings.

150 questions
2
votes
1 answer

ostringstream operator<< for long?

$ uname -a Darwin Wheelie-Cyberman 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 $ g++ --version i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) Copyright (C)…
phs
  • 10,687
  • 4
  • 58
  • 84
2
votes
2 answers

How do I perform string formatting to a static buffer in C++?

I am working in a section of code with very high performance requirements. I need to perform some formatted string operations, but I am trying to avoid memory allocations, even internal library ones. In the past, I would have done something similar…
Deon McClung
  • 191
  • 2
  • 8
2
votes
1 answer

double to string with ostringstream syntax

I'd like to understand why writing this static_cast( &(std::ostringstream() << speed.x) )->str(); makes a string, but not this (std::ostringstream() << speed.x).str();? in fact the latter doesn't even compile... I find this…
Sheed
  • 577
  • 4
  • 18
2
votes
2 answers

how to truncate width of integral types with std::ostringstream?

Say you have something like: std::ostringstream oss; int value(42); oss.fill('0'); oss << std::setw(3) << value; cout << oss.str(); OUTPUT: 042 This output is because std::setw ensures a minimum width and we told the stream to fill with 0 however…
AJG85
  • 15,849
  • 13
  • 42
  • 50
2
votes
2 answers

stringstream and multithreading

I'm new to multithreading and C++ and I'm having a problem when trying to use threads in my application which save files. The code is as follows: #include #include #include #include #include using…
Billy
  • 357
  • 1
  • 5
  • 14
2
votes
0 answers

Crash in std::basic_stringbuf::overflow

I'm testing a C++ library under Cygwin in a debug configuration. The debug configuration includes the following CXXFLAGS: -DDEBUG -g3 -O2 -D_GLIBCXX_DEBUG -std=c++03 The test is dying at: Testing PolynomialMod2 bit operations... Program received…
jww
  • 97,681
  • 90
  • 411
  • 885
2
votes
3 answers

Getting char* array from c++ stringstream ostringstream

I am trying to copy ostringstream to a char* array and am hoping someone can help me with understanding where my mistake lies. I looked on the forum, found some things that are similar and unfortunately am still am unable to get property copy from…
JavaFan
  • 1,295
  • 3
  • 19
  • 28
2
votes
2 answers

Truncate C++ string fields generated by ostringstream, iomanip:setw

In C++ I need string representations of integers with leading zeroes, where the representation has 8 digits and no more than 8 digits, truncating digits on the right side if necessary. I thought I could do this using just ostringstream and…
Ian Durkan
  • 1,212
  • 1
  • 12
  • 26
2
votes
1 answer

suppress "minus zero" from cout

double value; std::ostringstream s; s << std::fixed << std::setprecision(3) << value; When value wanders in the range -1.0e-14 to 1.0e-14, s flickers between "0.000" and "-0.000". Is there a clean way to suppress the minus sign, which only…
2
votes
2 answers

Crash when using "time.h"

==FINAL CLASS BENEATH THIS LINE== It was not an issue with std::ostringstream, I was doing bad things with "time.h" which I did not fully understand. The original question shows up after the class. The final class looks like…
shieldfoss
  • 886
  • 2
  • 12
  • 22
2
votes
3 answers

C++ Odd behaviour with ostringstream

Is there any explanation in the standard for the below behavior? The following code: #include #include using namespace std; int main() { ostringstream os1; ostringstream os2; os1 << 1 << " " << 2; os2 << 1 <<…
P.An
  • 355
  • 1
  • 9
2
votes
2 answers

trying to print from ostream but printing a blank instead

I have a lot of logging functions, which right now accept an ostringstream&. My goal is to make them able to accept a stream written in one line, something like this: MyPrint( ostringstream() << "hello!" << endl); I cannot change the method…
gil_bz
  • 478
  • 1
  • 5
  • 16
2
votes
1 answer

Copy contructor error with no obvious copy

I'm attempting to build a bit of simple logging functionality from scratch, with a stream like '<<' interface, and am running into a bit of compiler issue. Here is the basics of my code: #include #include #include…
WillW
  • 871
  • 6
  • 18
2
votes
1 answer

deserializing objects in C++

I know how to serialize an object in the following way: void encodeMsg(char **msg, const ConnectionParams& params) { std::ostringstream oss; if (!(oss << params)) { //failure } msg = oss.str(); } how can i deserialize a…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
2
votes
1 answer

Save away ostringreader.str().c_str()

Why does the value of text1 change after reading out y in this piece of code? void func() { int value1 = 5; double value2 = 1.5; std::ostringstream x, y; x << value1; y << value2; const char *text1 = x.str().c_str(); …
Civing
  • 353
  • 3
  • 12