Questions tagged [istringstream]

Anything related to C++ `istringstream` standard library class. This class represents an "input string stream", i.e. an input stream that allows a string to be used as the source of information attached to the stream.

Anything related to C++ istringstream standard library class. This class represents an input string stream, i.e. an input stream that allows a string to be used as the source of information attached to the stream.

istringstream is a specialization of the basic_istringstream template class and it is defined in C++ <sstream> standard library header.

See CPPreference.com on basic_istringstream template class.

216 questions
5
votes
4 answers

How to extract mixed format using istringstream

Why does my program not output: 10 1.546 ,Apple 1 instead of 10 1 here's my program: #include #include #include using namespace std; int main () { string str = "10,1.546,Apple 1"; …
Sunil Kundal
  • 143
  • 1
  • 2
  • 8
5
votes
2 answers

std::istringstream from std::string without copying

I've been using this: ifstream in("file.txt") string line; getline(in,line); istringstream iss(line); ... for some simple parsing. I would like to avoid unnecessary copying in order to improve performance so I tried: ifstream…
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
5
votes
2 answers

How to initialise a stringstream from a vector char

currently I am using a boost char array boost::array received_data; std::istringstream ss_(received_data.data()); but what if my received_data was a std::vector received_data(512); how would I then get this data to my…
user494461
5
votes
4 answers

How do I check that stream extraction has consumed all input?

In the following function, I try to see if a string s is convertible to type T by seeing if I can read a type T, and if the input is completely consumed afterwards. I want template bool can_be_converted_to(const std::string& s, T& t) {…
BenRI
  • 724
  • 6
  • 17
5
votes
2 answers

How to block on reading a c++ stringstream to wait for data

So, I've been trying to figure out, how to wait for data from a C++ stringstream (for instance), without being constantly checking if data is there, which is quite CPU consuming. I'm perfectly able to read, for instance, from a serial device, and…
cvicente
  • 132
  • 3
  • 12
4
votes
1 answer

"Off by one error" while using istringstream in C++

I get an off by one error while executing the following code #include #include #include using namespace std; int main (int argc, char* argv[]){ string tokens,input; input = "how are you"; istringstream iss…
shiraz
  • 1,208
  • 2
  • 12
  • 26
4
votes
2 answers

Why doesn't std::stringstream work with std::string_view?

The std::stringstream initialization constructor accepts const string& as a parameter: explicit stringstream (const string& str, ios_base::openmode which = ios_base::in | ios_base::out); This interface was reasonable in…
Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
4
votes
2 answers

Using istringstream in C++

I have some code that utilizes fork, execlp, and wait to make two processes. The objective is to be able to repeatedly print a prompt and have the user enter a command with up to 4 arguments/options to the command. int main() { string command,…
Drake Daniels
  • 71
  • 1
  • 1
  • 4
4
votes
1 answer

Undefined characters while reading the file content without new line at the end of file

File (settings.txt) to parse: FULLSCREEN=On V_SYNC=On [no "\n" at the end of file] In case with no ENTER "\n" output is: MapKey= FULLSCREEN MapValue= On MapKey= V_SYNC MapValue= Onřřřř With ENTER "\n" at the end of file output is correct…
user3455638
  • 569
  • 1
  • 6
  • 17
4
votes
0 answers

C++ istringstream tokenizing

I want to read a line from stdin and tokenize it by whitespace, using the istringstream class. But it doesn't work as expected: #include #include using namespace std; int main() { string input_line; istringstream…
Georg P.
  • 2,785
  • 2
  • 27
  • 53
4
votes
2 answers

stringstream with multiple delimiters

This is another question that I can't seem to find an answer to because every example I can find uses vectors and my teacher won't let us use vectors for this class. I need to read in a plain text version of a book one word at a time using (any…
user3776749
  • 667
  • 1
  • 10
  • 20
4
votes
1 answer

C++ istringstream and whitespace

I've got some input like this: (50.1003781N, 14.3925125E) which is stored in const string & input. What I'm trying to do is to extract the brackets, get the number representing the GPS coordination - 50.1003781, save N and do the same for the second…
kubisma1
  • 307
  • 5
  • 13
3
votes
1 answer

EXC_BAD_ACCESS when creating istringstream

This one's got me. I'm trying to write a templated function for converting a string into different data types. It has to be able to compile on twelve different platforms, so using boost isn't a convenient option. I've taken a step back to just…
Phil Viso
  • 643
  • 7
  • 11
3
votes
1 answer

Why does this extern "C" function not work using python ctypes?

I have the following c++ function that sets an integer using a string. #include #include #include using namespace std; extern "C" { int a() { int number; string value("100"); std::istringstream…
SiggyF
  • 22,088
  • 8
  • 43
  • 57
3
votes
2 answers

Searching for strings within a string in C++

everyone. I am an experienced C programmer trying to get adjusted to C++. I would like to do the equivalent of this C statement... sscanf(str, "%s %s", sub1, sub2); ...but with C++'s string object. Say str is "hello world", doing the above sscanf…
Tanner Babcock
  • 3,232
  • 6
  • 21
  • 23
1
2
3
14 15