Questions tagged [stringstream]

stringstream provides an interface to manipulate strings as if they were input/output streams.

Filter by
Sorted by
Tagged with
0 votes
0 answers
55 views

Issues with serializing and deserializing C++ libtorch tensors (stringstream -> string -> char* -> stringstream)

TLDR: Using torch::save and torch::load on std::stringstream works just fine to save and load tensors. However, transforming the std::stringstream to a std::string and then a char* to send over a TCP ...
pregenRobot's user avatar
1 vote
1 answer
401 views

Why is libfmt slower than stringstream append?

I have a codebase that uses business logic to convert csv files to xml-like config files. This code uses stringstreams heavily to construct the config files some of which has inline SQL statements in ...
enpassant's user avatar
1 vote
1 answer
33 views

stringstream good() return value with char vs. string

I would like to understand why ss.good() behavior is different when z below is a std::string vs. char, in particular why good() returns true in one case and false with other. #include <iostream> ...
user3882729's user avatar
  • 1,359
1 vote
1 answer
55 views

Convert boost::beast::multibuffer to std::istream

I am getting boost::beast::multibuffer object from http::response<http::dynamic_body>::body() method. Then, I want to parse json content from it like this: boost::property_tree::read_json(...
Стас's user avatar
  • 129
8 votes
1 answer
178 views

Can an strstream directly use the buffer of a standard string

Given that strstream has the following constructor: strstream( char* s, int n, std::ios_base::openmode mode); I was wondering whether I can use the buffer underlying a standard string directly, in &...
Lorah Attkins's user avatar
1 vote
1 answer
68 views

Streaming a stringstream within a stringstream Code compiles for GCC until V5.5 but not the following versions

I have the following C++ code that compiles successfully for gcc < v5.5 #include <sstream> namespace util { inline void operator << (std::stringstream& stream, const char* data)...
Bilal Ahmed's user avatar
0 votes
1 answer
49 views

Substitute std::ofstream's underlying rdbuf with std::stringstream's underlying rdbuf

#include <fstream> #include <ostream> #include <sstream> int main(int /*argc*/, char** /*argv*/) { auto ofs = std::ofstream{"out.txt"}; if (!ofs) { throw std::...
psb's user avatar
  • 342
1 vote
1 answer
87 views

std::stringstream gets broken after setting UTF8 locale

I'm having trouble with outputting numbers once I set a global locale in my C++ app. Here's a working code sample: #include <locale> #include <clocale> #include <sstream> #include &...
Bogdan Ionitza's user avatar
-1 votes
1 answer
54 views

C++ multi data text parse via regex [closed]

Text to be parsed: 001 B001C001_230130_RQ7V V C 04:23:30:18 04:24:14:01 01:00:00:00 01:00:43:08 *ASC_SOP (1.000000 1.000000 1.000000)(0.000000 0.000000 0.000000)(1.000000 1.000000 1....
hdcdigi's user avatar
  • 75
0 votes
0 answers
20 views

Converting double to string using iomanip (std::setprecision) not working probably

Code split below: #include <iostream> #include <iomanip> #include <sstream> using namespace std; int main() { double x = 121932631112635269; std::stringstream stream; stream <<...
Dat09's user avatar
  • 1
1 vote
1 answer
71 views

C++: How to read from a custom text file based on position/length of fields (no delimiter)?

I am new to C++, and have some issues reading from a custom text file. Suppose each line of the file includes the fields EXACTLY with the following format: A float starting at position 0, with length ...
SoSa's user avatar
  • 105
1 vote
2 answers
52 views

stringstream does not reset across several calls

I'm trying to load in input from a file, representing students. Each student has a name and list of scores, like so: Name John Wayne Scores 100 90 80 100 0 Name Bob Dwight Scores 0 0 10 100 Name ...
Kevin Li's user avatar
0 votes
2 answers
96 views

Why can't I put string into stringstream object?

I need to make a C++ program to enlist every word in sentence without repetition. I tried putting every word int stringstream object, but it doesn't put it at all?? Here's the code: #include <...
Nadja Popovic's user avatar
0 votes
0 answers
30 views

Find for file name that contains specific information and print that sorted files

I have taken out all the integers from the filenames and sorted the integers following an ascending order. However, I want to print the filenames following the ascending order of sorted integers, and ...
Cassey's user avatar
  • 17
0 votes
0 answers
24 views

How to see the content of a std::stringstream with gdb? [duplicate]

I don't manage to see the content of a std::stringstream object for debugging. Here is my code : #include <iostream> #include <sstream> int main() { std::stringstream ss; ss <...
Tesla123's user avatar
  • 319
2 votes
1 answer
83 views

Is there a way to conditionalize a C++ macro against the g++ version to work around this static-cast behavior-change between g++ 9.4.0 and 11.3?

The code below demonstrates that when streaming the return-value from std::stringstream::operator<< to a std::ostream instance, like std::cout, an explicit static_cast (from std::basic_ostream&...
StoneThrow's user avatar
  • 5,334
0 votes
1 answer
75 views

Why C++ string erase function in a stringstream declaration and initialization failed to work?

I've made a simple program. I'm reading a text file in the same folder as the program. The file only has one line: " v 1.0 2.0 3.0". Problem: When I initialize a stringstream instance ss ...
pg daszzz's user avatar
0 votes
3 answers
249 views

How to remove all the words from a string that start with a certain character in C++

I have to create a function in C++ that would remove all the words from a string that start with a certain character inputted by a user. For example, if I were to have a string "She made up her ...
blulow's user avatar
  • 39
0 votes
0 answers
59 views

Error: cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’ on generic value

I'm trying to check if a value is correct via a function template. The values that I check are all booleans or integers. If the values match, the function will return boost::none, otherwise it will ...
Typhaon's user avatar
  • 848
1 vote
3 answers
116 views

In C++ is there a way to call a function with a std::stringstream& argument without the caller using a named variable?

In C++, is it possible to call a function whose argument is std::stringstream& without the caller declaring an explicit named variable of type std::stringstream? I.e. I would like to accomplish ...
StoneThrow's user avatar
  • 5,334
0 votes
1 answer
37 views

How does this parsing function using stringstream work?

so I made a function to parse a given string with a comma delimiter last semester during a haze. Its very likely I took much of it from guides online, but it worked for the overall project so I did it....
RobertBarron's user avatar
0 votes
0 answers
84 views

std::stringsteam seems to break std::cout

#include <iostream> #include <sstream> int main() { std::stringstream ss1; std::cout << "hello"; } For some reason, on VSCode on my Windows PC, the std::cout ...
chids's user avatar
  • 25
0 votes
1 answer
93 views

C++ use std::stringstream operator>>instead of atoi [duplicate]

Instead of atoi I use operator>> of stringstream in the following function in order to convert a string into an int. int MyString::Int() { int f = 0; std::stringstream ss; ss << *...
Ernie Mur's user avatar
  • 481
0 votes
1 answer
100 views

Can I throwaway the last character of a std::stringstream?

This is basically what I want to do. int main(int argc, char* argv[]) { std::stringstream ss; ss << "12345"; ss.seekp(-1, std::ios::end); ss << '\0'; assert(...
MarkB's user avatar
  • 692
0 votes
0 answers
97 views

C++ Cereal XML-Archive not working with stringstream

I am trying to get cereal-serialization to work. But somehow it does not work with the XML-Archive in combination with a stringstream. Here is my example: std::stringstream ss; cereal::...
Philip Schulz's user avatar
-1 votes
1 answer
186 views

Writing to the stream buffer of a string stream overrides the previous data

What I want to do is to create string stream , and output stream, giving the buffer of string stream to output stream, so that it will output data to the string stream. Everything seems fine, but ...
Parviz Pirizade's user avatar
2 votes
1 answer
185 views

round error of C++ when using fixed and setprecision in stringstream

I wrote a program in C++ and I think the result of it should be 12.3 and 12.2. But the final result is 12.2 and 12.2. Obviously, it is not rounding rightly. But why? Thanking you very much :) #include ...
Lee's user avatar
  • 31
0 votes
0 answers
36 views

C++ 17 any variable being set to "not empty (Small)" rather than actual value

I am currently working on a project to handle RPN equations and solve them. This includes *, /, +, -, sin, cos, tan, parenthesis, integers, and doubles. I am attempting to use a stack of any-s to ...
Cory Eheart's user avatar
3 votes
3 answers
75 views

stringstream operator>> fails to assign a number in debug

I have this simple function that, given a string str, if it is a number then return 'true' and overwrite the reference input num. template <typename T> bool toNumber(string str, T& num) { ...
GiaMat45's user avatar
0 votes
0 answers
327 views

std::vector string whitespace manipulation

Given a string of which the content could be "this is a test string jump‎ ‏‏‎ ‎‎fox string". There are 2 things to note from this string - there is one space between every word, but also at ...
Mutlithrd's user avatar
0 votes
1 answer
67 views

Conversion to string if input may be a string with spaces and line breaks

I am trying to convert any input of arithmetic type or char or string (including spaces and or line breaks) to a string. I tried using to_string which works for any input but string. I then tried void ...
Mori's user avatar
  • 3
0 votes
1 answer
101 views

C++ stringstream question, how can I make each line seperate

I'm sorry the title may be inaccurate.I'm new to C++. Here is my code and output... #include <iostream> #include <sstream> using namespace std; class LogLine { private: stringstream ss;...
Alanaa's user avatar
  • 75
1 vote
1 answer
134 views

Streaming into `char` array with `ostream` - how to get characters written count?

This answer shows how to write to an array with stringstream, but can we obtain the total number of characters written? Surely the stringstream has some information to know where to put the next ...
acupoftea's user avatar
  • 193
0 votes
1 answer
52 views

basic_stringstream and its parent classes

Why is basic_stringstream is derived from basic_iostream and not from basic_istringstream and basic_ostringstream? What all gets derived from basic_istringstream and basic_ostringstream then? ...
Sreeraj Chundayil's user avatar
1 vote
1 answer
43 views

How to format padded signed numbers in a stringstream

I'm trying to format numbers using C++ streams and am having trouble with the sign character being placed after the fill instead of before. When I do this: std::cout << std::setfill('0') <<...
John Stephen's user avatar
  • 7,625
0 votes
0 answers
32 views

Format a decimal to string, whilst removing any trailing zeros and avoiding scientific notation [duplicate]

I want to remove trailing zeros from doubles whilst they're being converted to a string. For example, 0.9345750000 => 0.934575 and 0.6 => 0.6 I'm currently using this: std::stringstream ss; ss &...
intrigued_66's user avatar
  • 16.1k
0 votes
2 answers
96 views

Why does my stringstream get filled with garbage after tryng to insert the contents into a vector?

Consider the code: void someFunc { std::stringstream value; std::vector<std::vector<int>> mapLayerCollision; int row = 0; for(int i = 0; i < gid_list.length(); i++) { ...
DinoNuggies's user avatar
0 votes
1 answer
59 views

Putting a stringstream at the beginning of another

I'm putting information in a stringstream, but just at the end of it, just adding stuff. But I need to now put something at the beginning of the one I'm adding stuff to. Example: std::stringstream ...
Ricardoke's user avatar
  • 143
0 votes
1 answer
201 views

How to convert a char16_t into a stringstream divided with 2 bytes

I made a utf8 to utf16 conversion where i get the code units for the utf16 char16_t. { std::string u8 = u8"ʑʒʓʔ"; // UTF-8 to UTF-16/char16_t std::u16string u16_conv = std::...
Ricardoke's user avatar
  • 143
0 votes
2 answers
513 views

How to write string stream to ofstream?

I am trying to write a stringstream into a file but it not working. int main() { std::stringstream stream; stream << "Hello world"; cout << stream.rdbuf()<<...
lorem1213's user avatar
  • 433
0 votes
0 answers
22 views

Confused by how stringstream seems to work [duplicate]

using stringstream to read individual words from a sentence vs using it to parse comma separated integers behaves differently than how I expected it to. string ok = "hello how is it going"; ...
raultoks's user avatar
1 vote
1 answer
70 views

Why can't I run my getline code without the stringstream? How do i use stringstream to make this code work?

#include<iostream> #include<string> using namespace std; int main() { string randomwords,temp; getline(cin,randomwords); while(getline(randomwords,temp,' ')) { ...
Henryychangg's user avatar
0 votes
1 answer
130 views

socket write in for loop mixes string buffers

I call a function multiple times using a for loop like this: for ( int con=0; con < this->controller_info.size(); con++ ) { try { this->pi.home_axis( this->controller_info.at(con)....
astronomerdave's user avatar
0 votes
0 answers
83 views

Read specific Type from stringstream containing hex representation of data on C++

I am trying to use a stringstream to read through hex representation of serialized data which I can get from a DB or a file, eg "11007B000000..." so if I call a function called ReadShort the ...
orlando9427's user avatar
-1 votes
1 answer
55 views

reading from a file and getting all strings after a string

I have something like this: while (getline(names_f, line) && getout == true) { istringstream linestream(line); linestream >> student_id >> student_name >> ...
Oprasis's user avatar
1 vote
1 answer
495 views

Is there a way to directly translate C's "%02x" format to C++? [duplicate]

I am following a tutorial in which they use BIO_printf(bio_out,"%02x",bs->data[i] ); in order to get the characters of a serial number stored in bs->data (which is an array of unsigned ...
user18743773's user avatar
3 votes
1 answer
56 views

Does the C++ standard guarantee that when the return value of 'rdbuf' passed to the stream output operator, he conent of the buffer gets printed out

Consider the following code snippet: std::stringstream ss; ss << "hello world!\n"; auto a = ss.rdbuf(); std::cout << a; // prints out "hello world! The variable a is a ...
John Z. Li's user avatar
  • 1,893
0 votes
1 answer
181 views

On the conversion from std::string type to template T type in C++

I've found on this forum the following snippet witten by user Ben Voigt: //forward declaration template<typename T> T getline_as(std::istream& s); template<> std::string getline_as<...
user17973316's user avatar
1 vote
1 answer
184 views

std::stringstream's seekg does not work after while loop

I have this std::stringstream object whose contents I have to read (only) twice. For this I thought I could use its seekg member function to repeat the reading. But I can't make it work. Here's a MWE ...
Lluís Alemany-Puig's user avatar
0 votes
0 answers
184 views

Passing istream and string as functions parameters

I have the following code. What I'm trying to do is implement a word count function similar to wc in unix. It takes a file as input and gives back the number of lines, words and characters in that ...
r3k0j's user avatar
  • 91

1
2 3 4 5
24