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
-1
votes
1 answer

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 when I try to add data to buffer of the string…
Parviz Pirizade
  • 193
  • 2
  • 12
-1
votes
1 answer

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 >> student_surname; As long as I have a function to consider if there is a middle name…
Oprasis
  • 9
  • 2
-1
votes
1 answer

How to prevent C++ string stream from reading double into int?

I want to write a function that reads an integer from a string and throws errors when encountering invalid inputs. Invalid inputs include non-digit and non-integer inputs. The following function detects non-digit inputs as invalid input but does not…
-1
votes
1 answer

Problem extracting formatted input from an istringstream that has been set twice

Thanks for the help. My program reads lines from stdin. The first one has a single number which determines the mode at which the program is running, and the rest contain sequences of numbers of undetermined length. The number of lines is determined…
-1
votes
2 answers

std::getline() does not ignore white space

I am new to C++ and I have some trouble preventing getline to read the new line character at the end of my text file. I tried truncating it using a newline character and then passing to a delimiter with ',' but it just doesnt work. Can you please…
-1
votes
1 answer

Difference between using << operator with stringsteam and write member function

I have observed that when a uint8_t type buffer (not guaranteed to be null terminated) is read into a stringstream with the << operator using ss << buff.data, and the contained std::string is returned to Python, Python throws an…
yashC
  • 887
  • 7
  • 20
-1
votes
1 answer

Issue with stringstream/osstream not chaining << operator and never calling flush at std::end

So I have the following logging class #include #include #include #include struct asDigest { explicit asDigest(const void* text, size_t len) : _t(text), _l(len) {} explicit asDigest(const std::string&…
-1
votes
1 answer

How can I pass std::basic_streambuf* into a function without #define

I have a simple log class that I want to use for logging which file, line, and function created the log message. I am passing the information in the following way: Logger::Log(LoggerLevel::ERROR, __FILE__ << ":" << __LINE__ << "::" << __FUNCTION__…
Xilnik
  • 1
  • 1
-1
votes
1 answer

About array in stringstream in C++

I want to design a program that inputs a string with space and output split string and the number of letters, but I don't know what the "word[]" means in "while (!ss.eof()){}". For example, I input "Programming is fun", the result…
timeil0611
  • 39
  • 1
  • 1
  • 7
-1
votes
1 answer

C++ "incomplete type is not allowed" when using stringstream

I have the following C++ code #include int main() { std::string sText = "These are words in my string!"; std::string sWord; std::stringstream ss(sText); } And it works fine on Fedora with g++. However, running it on Windows…
Dock
  • 444
  • 5
  • 13
-1
votes
2 answers

Splitting a string in c++

I'm writing a function to reverse words in a string. My idea is to split a string by ' ', push the words into a stack and pop them out to print the string with their words reversed. But , I am not able to split the string using stringstream…
AnonymousMe
  • 509
  • 1
  • 5
  • 18
-1
votes
1 answer

I can only access elements of a vector while inside a for loop

I have a function with a vector that is passed in by reference. I am able to use the vector inside a for loop to write its contents to a file. However, if I try to access any index of the vector outside of the loop, is gives me this error: terminate…
janksmap
  • 61
  • 1
  • 2
  • 7
-1
votes
1 answer

Stringstream & char*[] segmentation fault

On my computer (Win10, WSL 1, Ubuntu 20.04) This code would compile and run correctly, #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); char *test[30]; string a; …
Peter Qiu
  • 103
  • 1
  • 6
-1
votes
1 answer

Can I ask and store input that can be both numbers or characters and use it in conditional expressions?

I am trying to use stroi in my "vending machine" code below. I had a working vending machine before I tried to add a feature that allows users to enter characters ("c" for checkout, "a" for add, and "r" for remove) as well. Since my user input can…
yeliah
  • 41
  • 6
-1
votes
1 answer

Unable to use stringstream to read in int and double

#include #include //for istringstream int main(){ std::istringstream iss; std::string tempSTR; int A; double B; std::cout<<"Please enter an int.\n"; std::cin>>tempSTR; iss.str(tempSTR); …