Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

stringstream with multiple delimiters

If you are free to use Boost, you can do the following:

$ cat kk.txt
If they had known;; you ... wished it, the
entertainment.would have

You can customize the behavior of tokenizer if needed but the default should be sufficient.

#include <iostream>
#include <fstream>
#include <string>

#include <boost/tokenizer.hpp>

int main()
  std::ifstream is("./kk.txt");
  std::string line;

  while (std::getline(is, line)) {
    boost::tokenizer<> tokens(line);

    for (const auto& word : tokens)
      std::cout << word << '

  return 0;

And finally

$ ./a.out

Categories : C++

Related to : stringstream with multiple delimiters
C++ stringstream error handling
Once a stream moved into fail state, it will stay in fail state until gets clear()ed. That is, you need to do something like this: if ( { std::cout << "This is not an integer "; ss.clear(); // ... } Also not that just writing to a string stream does not replace the string stream's content! to replace the content of a string stream you can use the str() method: ss.s

Categories : C++
extract from stringstream into 2D vector
You are using getline and stringstream, which are good tools, but not the right tools for this job; they are too powerful and require too much care. Rather than analyze exactly how they are going wrong, look at what happens when we dispense with them, in favor of stream input: void beolvas (vector<vector<double> > & mygraph, string filename) { ifstream input(filename.c_str());

Categories : C++
Split a Linestring with Delimiters
you don't need to develop new function - PostgreSQL has nice function - string_to_array(string, delimiter) postgres=> select string_to_array('1.0 2.0 3.2', ' '); string_to_array ----------------- {1.0,2.0,3.2} (1 row) postgres=> select * from unnest(string_to_array('1.0 2.0 3.2', ' ')); unnest -------- 1.0 2.0 3.2 (3 rows) Parsing strings in plpgsql is wrong idea - some operatio

Categories : String
Meteor and AngularJS delimiters conflicts
Yes, this is a very annoying thing... AngularJS is amazing for letting you do that but Meteor does not. In the meantime, there are a lot of packages that developers wrote that take care of that for you, Ionic for example: Another possible solution is to use Gulp or Grunt or create a task that scans all templates in your Meteor project and changes them to [[

Categories : Angularjs
Deleting certain pieces of values in between delimiters- SQL server
Convert the string into rows using the delimiter ; From the converted rows remove the unwanted Emails. After removing convert the rows into single string delimited with ; CREATE TABLE #delemail (email VARCHAR(5000)) INSERT INTO #delemail VALUES ( ';;;') DECLARE @email VARCHAR(500)='' SELECT @email += ';' +

Categories : SQL
Recently Add
C++: error C2143: syntax error : missing ';' before '<'
Converting 2s compliment to a decimal. Output is double
how do you compare a string to a vector value?
Converting a long double to double with upward (or downward) rounding
C++: operator<< overloading in the nested classes
Unclear behavior with csv processing using getline
C++ Visual Studio Error: IntelliSense: expected a statement
Game of Nim - showing the remaining numbers and letting a player pick their name?
malloc 1D array in struct
How to create an array of smart pointers?
c++ swapping unique_ptr's
Functions as arguments
Any Fast & Efficient way to generate a 3D Grid?
Is string[] not a type?
C++ typeid(x).name() returns ph
Counting / Printing Path - From (1,1) to (m, n)
C++ input function that calls itself
Error: array must be initialized with a brace-enclosed initializer
SDL_ConvertSurface() causes break
C++ std deviation function?
libcURL Progress Function not being called
What is QList's maximum size?
Run batch with C++
Read a file and write its contents to another C++
extract from stringstream into 2D vector
How to stop Scons adding lib infront of a shared library
Blocking vs non-blocking mode in TCP sockets using C++
SDL2 toggle SDL_WINDOW_RESIZABLE state for fake fullscreen
How can I assign value to specific vector's index?
Operator Overloading with Constant Iterators
© Copyright 2017 Publishing Limited. All rights reserved.