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
0
votes
0 answers

Eliminating the extra copy when using getline + istringstream to parse cin inputs?

As my example, I am reading input in a CSV format. I need to take a line as input and then parse it. Example The standard suggestion for parsing lines of std::cin inputs looks like the following: #include #include #include…
user589321
  • 99
  • 6
0
votes
1 answer

seek from end of a istringstream fails

Here is a minimalist code : #include #include #include int main () { std::string str = "spam" ; std::istringstream isz( str ) ; isz.seekg( 1,std::ios_base::beg ) ; std::cout << isz.fail() ; …
Captain'Flam
  • 479
  • 4
  • 12
0
votes
1 answer

Extracing words that start with '#' from a string into a stringstream- C++

I am trying to write a program that will return words that start with the symbol # from a string. For example: A string such as "I like #tacos and #pizza" would return: #tacos #pizza This is my current code: int main(void){ string myString = "I…
0
votes
1 answer

Using an istringstream With ASCII 26 Character

I have a fairly simple ask, but I haven't been able to find any help anywhere, so I was hoping for some help. I'm working with some C++ stringstreams and I have string data that is causing my stream to fail. Specifically, the stream fails when I…
Josh B.
  • 157
  • 7
0
votes
2 answers

How to read from std::cin to istringstream

I would like to parse date in format [mm/dd/yy]: #include #include #include #include int main() { struct tm time; std::istringstream ss; std::cout << "enter string [mm/dd/yy/]: "; std::cin >>…
milanHrabos
  • 2,010
  • 3
  • 11
  • 45
0
votes
1 answer

expected primary-expression before ‘)’ token error on a while loop in a function

My issue is that I keep getting the "expected primary-expression before ')' token" error on the variable "string" in the while loop in the NumWords function. The variable works fine in the "istringstream inSS(string);" line but when I try to compile…
0
votes
0 answers

C++ | pushing string into empty vector causes first element to be corrupted?

I've been working on a *.csv parser and it works for the most part. Basically the parse works like this: Open a stream for the designated *.csv file (filepath, number of data columns, and a delimiter must be supplied at constructor). Get each line…
0
votes
0 answers

string tokeniser, delimiter and making objects with file input

I have a file that have multiple lines of the sample data given in the code. Each line is an object. I've been trying to work with string tokenizer but I keep getting errors. #include #include #include #include…
wakanada
  • 115
  • 1
  • 9
0
votes
0 answers

Testing for number failing with std::istringstream

I'm trying to ask the user to enter a number, repeatedly until they do. The code below runs fine if user enters a number on the first try. However if they enter a non numeric character first, then a number, the loop never breaks as I would…
Eon
  • 149
  • 8
0
votes
2 answers

Why am i getting error when i try to assign string to istringstream object in visual studio in c++?

The following class takes a string line as input from the user. My aim is to store it in the istringstream iss and then to extract various data from the istringstream iss into various variables. But, when I try to initialize iss with string…
0
votes
1 answer

Slow file reading with istringstearm and get line

I am trying to write a parser to read large text file in C++. Similar python code using readtable method is approximately 7 to 8 times faster. I am wonder why it runs so slow in C++. Most of the time is taken in using istringstream to parse lines to…
0
votes
2 answers

how to read and parse text files with istringstream?

I am trying to read a .txt file line by line: vector> iVecGrid; vector iVecRow; ifstream text; text.open("grid.txt", ios::in); if (!text) { cout << "Error!\n"; return EXIT_FAILURE; } istringstream isLine; string…
UnboxTheCat
  • 29
  • 1
  • 3
0
votes
0 answers

How to split a line given a delimeter

I have a basic_string of text. There are always 5 words on the line separated by |. I have made that string into a istringstream and i have tried this: istringstream MyStream(line_of_text); char cDelim; basic_string…
user12151735
0
votes
1 answer

Extracting complete current line from std::istream

I am scanning text coming from a std::istream. The scanning is already under way, and I would like to extract the line that is currently being read (from beginning to end). This getCurrentLine() function must not modify the std::istream position. I…
Touloudou
  • 2,079
  • 1
  • 17
  • 28
0
votes
1 answer

How To Read Multiple Integers from a String C++

I'm trying to understand how can I convert multiple integers from a string. I have tried to use atoi(), stoi() and istringstream() and they all do the same thing. I can't get more than one integer. For example, if the string is "Chocolate and Milk…
Joe
  • 83
  • 9