Questions tagged [sstream]

111 questions
127
votes
4 answers

What exactly does stringstream do?

I am trying to learn C++ since yesterday and I am using this document: http://www.cplusplus.com/files/tutorial.pdf (page 32). I found a code in the document and I ran it. I tried inputting Rs 5.5 for price and an integer for quantity and the output…
user3104350
26
votes
1 answer

How do I use the ostringstream properly in c++?

I am attempting to return some information when my toString() method is called, which include an integer and some floats. I learned about ostringstream works great but when the class that contains this method is called over and over again, the…
Arminium
  • 391
  • 2
  • 6
  • 12
18
votes
3 answers

aggregate 'std::stringstream out' has incomplete type and cannot be defined [C++]

I am new to c++ please help me figure out what is wrong with this string c; stringstream out; //aggregate 'std::stringstream out' has incomplete type and cannot be //defined out << it->second; out << end1;//'end1' was not declared in this scope c =…
Technupe
  • 4,831
  • 14
  • 34
  • 37
12
votes
4 answers

How to parse complex string with C++?

I'm trying to figure out how could I parse this string using "sstream" and C++ The format of it is: "string,int,int". I need to be able to assign the first part of the string which contains an IP address to a std::string. Here is an example of this…
Goles
  • 11,599
  • 22
  • 79
  • 140
8
votes
3 answers

Have a C++ Class act like a custom ostream, sstream

I have a C++ class MyObject and I want to be able to feed this data like I would to a osstream (but unlike a direct sstream, have the incoming data be formatted a special way). I can't seem to figure out how to overload a operator for MyObject to…
The Unknown
  • 19,224
  • 29
  • 77
  • 93
8
votes
1 answer

What value should `std::stringstream::fail()` return after reading then writing? (gcc vs clang)

Consider the following code snippet: #include #include int main() { std::stringstream ss; ss << "12345"; unsigned short s; ss >> s; ss << "foo"; std::cout << std::boolalpha << "\nss.eof() …
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
6
votes
2 answers

Why is stringstreams rdbuf() and str() giving me different output?

I have this code, int main() { std::string st; std::stringstream ss; ss<<"hej hej med dig"<str() : " << ss.rdbuf()->str(); std::cout <<"ss.rdbuf() : " <<…
mslot
  • 4,959
  • 9
  • 44
  • 76
5
votes
1 answer

sstream redeclared with public access compiler error

I came across this error when running make on a large project using gcc5.4.0. /usr/include/c++/5/sstream:300:14: error: '__xfer_bufptrs' redeclared with 'public' access struct __xfer_bufptrs ^ /usr/include/c++/5/sstream:67:14:…
miro_x
  • 201
  • 3
  • 8
5
votes
3 answers

Use an Anonymous Stringstream to Construct a String

I want to read directly into a string with code like this: std::string myString(( std::ostringstream() << myInt << " " << myFloat << " " << std::boolalpha <<…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
4
votes
2 answers

Stringstream when iterating through string doesnt work

So i want to use string stream to convert strings to integers. assume everything is done with: using namespace std; a basic case that seems to work is when I do this: string str = "12345"; istringstream ss(str); int i; ss >> i; that works…
user3651193
  • 51
  • 1
  • 1
  • 6
4
votes
4 answers

Error C2143: syntax error : missing ';' before 'namespace'

I am VERY new to C++ and Open GL and I have been trying to display 3D objects in a scene. it worked fine with one but when I tried to alter my code to add a second, my code regarding the HUD text showing the camera location started giving errors.…
Rainbowdave
  • 79
  • 1
  • 1
  • 5
3
votes
2 answers

Can't import both sstream and iostream in C++20?

Create a new empty C++ Windows console application in Visual Studio 2022. Add a "main.cppm" file and populate it with this: import ; int main() { std::stringstream ss; ss << "Hey world!"; return 0; } It should compile and run…
Todd Burch
  • 200
  • 8
3
votes
1 answer

How should I make my program correctly handle all user inputs?

I want to create an input system that can correctly handle all inputs. The desired user input is an double. When the user inputs a string, the stringstream fails and the exception is handled. However, the program can't handle inputs such as "3245…
H.F.
  • 29
  • 2
3
votes
2 answers

Passing unknown classes to String Streams in C++

I am using a template function and I am passing and I may be sending instances of a variety of classes to a string stream. What can I do to make sure this continues to work? Let me be more specific where do I define the behavior for this? Is there…
Sqeaky
  • 1,876
  • 3
  • 21
  • 40
3
votes
3 answers

convert string to int use sstream

We want to convert string to int using sstream. But we don't know our string has an integer or not, for example it can be the "hello 200" and we want 200 in that, or it can be "hello" and there was no solution! I have this code when we have only an…
1
2 3 4 5 6 7 8