Questions tagged [sstream]

111 questions
1
vote
3 answers

Extracting lines from .txt file, then store words into separate arrays | C++

Our professor gave us this assignment, where we have a .txt file with the following format: John 23 Mary 56 Kyle 99 Gary 100 ...etc. etc. What we have to do is read the file, and store the names and scores in parallel arrays. This is turning out to…
rcorrie
  • 921
  • 8
  • 26
0
votes
2 answers

what is c++ writing to the socket when an enum gets written

What is getting written to the socket when I write an ENUM reference (below)? I have something captured in whireshark but it does not resemble the ENUM name "JOIN" .. it is not the same length either. The server somehow understands that this code…
jcalfee314
  • 4,642
  • 8
  • 43
  • 75
0
votes
1 answer

How can I store in an struct member and after that print them using Serial.println() if the data to store is a stringstream?, framework arduino ESP32

I'm trying to print some data that I received as a string and for that I'm using the following function (FechaProg definition after the function) uint8_t Extrae_Data(string trama, FechaProg* destino ,char sep) { uint8_t contador = 0; string…
vram
  • 85
  • 8
0
votes
1 answer

The integer token that I need is behind characters so istringstream is not tokenising it

int integers; std::list integersList = {}; string token; while(iss >> token) { if(stringstream(token) >> integers) { integersList.push_back(integers); } } One of the tokens I need to parse is U54778
0
votes
0 answers

How do you catch the output of a void function that takes ostream as a parameter into a stringstream?

Let's say we have: void print(std::ostream &o) { o << "Hello World!"; } and: int main() { std::stringstream ss; ss << print(std::cout); // does not work std::string outputString = ss.str(); std::cout << outputString <<…
nasiedlak
  • 19
  • 1
  • 3
0
votes
1 answer

C++ read only integers in an fstream

How do I read in a file and ignore nonintegers? I have the part down where I remove the ',' from the file, but also need to remove the first word as well. #include #include #include using namespace std; above is all…
Taslosis
  • 3
  • 2
0
votes
3 answers

Is there any easy way to read a line from a file, split the first text part into a string, then split the last number part into a float?

I have an issue that I haven't been able to find a good way to solve, mostly because I am relatively new to C++, but not new to programming. I have a file with several lines in it, one of them being: Plain Egg 1.45 I need to be able to read that…
0
votes
2 answers

Use of sstream causing a deleted copy constructor

So I am a CS student working on a project for exception handling (Try/catch). My teacher told us to implement the sstream library so we could use it in a class that outputs a message that includes a passed parameter of type int. For some reason…
0
votes
0 answers

using sstream with complex numbers

I am trying to read a list of complex numbers from a txt file given as: 3+5i 2-3i 11+22i However when i use stringstream(oneline)>>real>>plusorminus>>im>>ichar; the real part is okay but the im part always shows up as 0. I tried to debug it by…
0
votes
1 answer

How do I use c++ stringstream to convert a string to a double? The string is a nonstandard scientific notation that does not contain 'e'

I have a code that looks like the following #include #include using namespace std; int main(){ string s = "-1.42-14"; stringstream ss; ss << s; double a ; ss >> a; cout << "a = " << a << endl; } I run…
Max
  • 1
0
votes
1 answer

istringstream split_string(line) how to update the split_string while changing line without using while loop?

line = "hello 2021" istringstream split_string(line); was a useful code to get the values from a string, i.e. split_string>>str>>temp_double; However, suppose that the value of line was changed, i.e. line="hello world" ,and one wanted to write…
0
votes
1 answer

sstream vs for loop speed for processing a string

I was wondering wether sstream is faster than just a for loop for processing a string? say for example we have a string that we can't to separate just the words: std::string somestring = "My dear aunt sally went to the market and couldn't find what…
jrubix
  • 67
  • 1
  • 8
0
votes
1 answer

How to know the format of the parameter inside a function C++

I have been trying to make a Convert.To command like in C# in C++ but I dont want to do it like "IntToString" Instead I want to make it like "ToString" just like in C#. I was wondering how can I know the format of the parameter given inside the…
user8760664
0
votes
2 answers

Running function with ifstream and stringstream multiple times

Im fairly new to c++ and i would like to ask for suggestions / advice if there is a better / more optimal way to use a function calling ifstream and string stream. I have a document with the structure with 150 lines and 8 columns (a small subset…
RAHenriksen
  • 143
  • 2
  • 12
0
votes
0 answers

Counting number of repetitions in a sorted text file C++

I have a file that looks like this: aaaabbcddd I'm using fstream and sstream to read it, and what i want to achieve is to read through it counting how many times a single element is repeated, so i can add a node to a BST with the repetition count…
cheveuxdelin
  • 127
  • 2
  • 9