Questions tagged [stringstream]

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

The objects of this class maintain internally a pointer to a stringbuf object that can be obtained/modified by calling member rdbuf. This streambuf-derived object controls a sequence of characters (string) that can be obtained/modified by calling member str.

1178 questions
-2
votes
1 answer

std::stringstream like a private variable in class

I want to use std::stringstream like a private variable in my class. But i have an error "undeclared identifier". PLease, explain why and get me advice how can i do this. class Test { private: std::stringstream str; }
Artyom Rusak
  • 27
  • 1
  • 5
-2
votes
6 answers

Copy float to string

I want to copy the contents of a float to a string in C++. This doesn't work. #include #include using namespace std; int main() { float ans = getFloat(); stringstream ss; string strAns; ss >> ans; strAns =…
ofey
  • 423
  • 1
  • 7
  • 17
-3
votes
2 answers

In C++, how can I use wstringstream to combine/concat wstring + NULL + DWORD

I want to create a wstring which will have a wstring + NULL + DWORD e.g. L"Text" + NULL + 0x001A. Can I use wstringstream to create such string which has a string ending char "\0" in between ? hex:54,00,65,00,78,00,74,00,00,00,00,00,1a,00 T …
Alex
  • 11
  • 2
-3
votes
4 answers

How would you pass a string to a function and return an integer?

I found that I needed to start using getline(cin, input); for my user inputs. I figured out how to use stringstream to convert a string from a user into an int, so that I can store and use the numbers in math functions. As an example, say you need…
JRuxDev
  • 17
  • 1
-3
votes
1 answer

How do I return a string from server to client in C?

I need to send a string back to client that includes the cost of vehicle and the vehicle with modifier(carStyling). I want to return a string containing the sline and the cost to the client. Something like; Your Sedan Offroad will cost…
-3
votes
1 answer

When converting a string array of numbers to an array of integers the elements are turned to 0s

When I convert info to integers and print out the array, the output is just 0s. Each element in info is a number entered as a string that was taken from a text file. For example: 513497628 19 4 16 4 7 14 18 15 10 6 6 1 7 17 88 10 79. I used strtok…
cdecaro
  • 3
  • 2
-3
votes
1 answer

Why is my output corrupted?

I'm using the following function to return the current amount of memory installed: const char* Aries::Memory::GetInstalledMemory() { MEMORYSTATUSEX statex; statex.dwLength = sizeof(statex); GlobalMemoryStatusEx(&statex); …
AStopher
  • 4,207
  • 11
  • 50
  • 75
-3
votes
1 answer

Code can't accept file that exceeds array size?

Below I have my current code for a project I am working on. It is meant to take a file of students and their grades, average the grades, and then place them all back into an output file. The amount of students should not exceed 10, so if there is…
-3
votes
3 answers

print sum if all inputs are valid otherwise print "Invalid" in c++

The problem is to print sum of all integers in one input line.If any of the input is not valid print "Invalid". This is the code --> C++ Code Link The problem with the code is that it doesn't produces output if input > 9 .How should I approach…
close2zero
  • 85
  • 8
-3
votes
1 answer

Stringstream vs. type casting in C++

How does using stringstream to extract an integer value from a string differ from simply using explicit value casting to change the type? Example: string a = "1234"; int x; x= int (a); vs. string a = "1234"; int x; stringstream (a) >> x;
Marcel
  • 115
  • 4
-3
votes
1 answer

C++ How do i add a string to an existing text file without overwriting it?

I have coded a programm which can load one text file, can decide how long each word is and can write txt files based on the length of the words. But when i run the programm, the new text files are always filled with just one word(each new word with…
Jordan Zapf
  • 65
  • 1
  • 11
-4
votes
2 answers

Stringstream variable does not show in binary code?

why stringstream query variable does not work? std::stringstream query (stringstream::in | stringstream::out | stringstream::binary); for(vector::iterator it=buff.begin();it !=buff.end();it++) { query<<*it; …
Tansistem
  • 1
  • 1
-4
votes
2 answers

Why c++ has iostream when it has istream and stream?

According to my test in vs2019, ostream takes 72 bytes, istream takes 80 bytes and iostream takes 88 bytes. There is no discernible difference in their size, so I don't think 'it's aimed at saving resource' is right. Another confusing problem is why…
-4
votes
1 answer

stringstream to variables with an unknown separator

I have converted a few numbers to a string with a separator from type of string as follows #include #include #include std::string vars_to_string(std::string separator, double object_x, double object_y, double object_z,…
ar2015
  • 5,558
  • 8
  • 53
  • 110
-4
votes
1 answer

How could I search and modify numbers surrounded by certain patterns from a string in C++?

I am trying to process a string with a random size, and modify all numbers surrounded by certain patterns. For example, string oldstring = "res 0.25 cap 0.12 tra 1 res 0.3 cap"; string newstring = "res 0.50 cap 0.12 tra 1 res 0.6 cap"; So all the…
HumbeCoder
  • 33
  • 2
1 2 3
78
79