116 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
1
answer
104
views
read double value from a file: std::invalid_argument after std::stod call
#include <iostream>
#include <fstream>
#include <sstream>
int main() {
std::ifstream file("data.txt");
std::string line, numStr;
// read first line
std:...
0
votes
0
answers
52
views
how to convert string in date format to UNIX time? c++ [duplicate]
char sDateAndTime[80];
time_t t;
t = 1643873040;
tm *timeinfo = localtime( &t );
strftime( sDateAndTime, 80, "%d/%m/%Y, %H:%M:%S", timeinfo );
std::cout << sDateAndTime;
i have ...
-2
votes
1
answer
86
views
Splitting a compact string into individual ints [closed]
I am attempting to write a program that reads a file line by line, and storing the contents of each line as individual integer values. A typical line might look like this:
7190007400050083
The ...
0
votes
2
answers
145
views
stringstream to int ignore trailing whitespace [duplicate]
I am trying to read all the numbers a line of text, one by one.
Here is a minimal reproducible example of my code:
#include <iostream>
#include <sstream>
int main() {
std::string line ...
-1
votes
1
answer
116
views
I'm having issues finding binary substring in my BMP file
so i have a small issue. I am working on a school assignment and i just can't figure out how to get the solution. So the assignment needs me to read a file in binary form and then find certain bit ...
1
vote
1
answer
57
views
C++: serialization using sstream
I am testing a serialization code below, which fails for a few numbers. Any idea?
#include <iostream>
#include <sstream>
int main()
{
std::stringstream ss;
for (unsigned int m = 0; ...
3
votes
2
answers
914
views
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 <sstream>;
int main()
{
std::stringstream ss;
...
0
votes
1
answer
631
views
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 ,...
0
votes
1
answer
81
views
The integer token that I need is behind characters so istringstream is not tokenising it
int integers;
std::list<int> integersList = {};
string token;
while(iss >> token)
{
if(stringstream(token) >> integers)
{
integersList.push_back(integers);
}
}
...
0
votes
0
answers
198
views
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::...
0
votes
1
answer
152
views
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 <iostream>
#include <...
0
votes
3
answers
396
views
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:
...
1
vote
1
answer
761
views
Read text file containing 2D matrix and associated data
I have a text file structured like this:
6
0,2,0,0,5,0
3,0,4,0,0,0
0,0,0,6,1,0
0,0,0,0,2,0
0,0,0,0,2,4
1,0,0,0,0,0
0,5
The first number represents the number of vertices and the 2D matrix is an ...
0
votes
2
answers
361
views
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 ...
0
votes
0
answers
179
views
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 ...