Here is a (maybe less verbose) way to split string (based on the post you mentioned).
#include <string> #include <sstream> #include <vector> std::vector<std::string> split(const std::string &s, char delim) { std::stringstream ss(s); std::string item; std::vector<std::string> elems; while (std::getline(ss, item, delim)) { elems.push_back(item); // elems.push_back(std::move(item)); // if C++11 (based on comment from @mchiasson) } return elems; }
Related Posts:
- How do I iterate over the words of a string?
- How do I iterate over the words of a string?
- How do I tokenize a string in C++?
- C++: std does not have member “string”
- convert string to size_t
- Why the switch statement cannot be applied on strings?
- How to convert string to char array in C++?
- How can I convert a std::string to int?
- Easiest way to convert int to string in C++
- What is a lambda expression in C++11?
- std::string to char*
- How to convert string to char array in C++?
- C++ — expected primary-expression before ‘ ‘
- ld: symbol(s) not found for architecture x86_64 error
- C++ string to double conversion
- Conversion from string to char – c++
- What is `CString`?
- What is the ‘override’ keyword in C++ used for? [duplicate]
- What is a smart pointer and when should I use one?
- Meaning of = delete after function declaration
- C++ std::priority_queue uses the lambda expression
- Usage and Syntax of std::function
- How do I include the string header?
- What exactly is nullptr?
- Differences between C++ string == and compare()?
- How to convert a char array to a string?
- Difference between `constexpr` and `const`
- How do I convert a double into a string in C++?
- How to create timer events using C++ 11?
- How to convert an instance of std::string to lower case
- Check if a string contains a string in C++
- Returning an empty string : efficient way in c++
- Replace part of a string with another string
- C++ string to double conversion
- What is use of c_str function In c++
- How to reverse an std::string? [duplicate]
- What does T&& (double ampersand) mean in C++11?
- C++ Parsing input string to variables
- Segmentation fault error 11 C++
- Why doesn’t C++ have a garbage collector?
- Compiling C++11 with g++
- terminate called after throwing an instance of ‘std::invalid_argument’ what(): stoi
- std::string to char*
- What exactly is std::atomic?
- Issue with std::stol – ‘std::invalid_argument’ what(): stol
- terminate called after throwing an instance of ‘std::out_of_range’
- How to convert a std::string to const char* or char*
- Cleanest way to copy a constant size array in c++11
- Why use string::iterator rather than index?
- push_back vs emplace_back
- Why am I getting string does not name a type Error?
- undefined reference to ‘std::cout’
- What is move semantics?
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- C++ error: Undefined symbols for architecture x86_64
- C++ deprecated conversion from string constant to ‘char*’
- C++ terminate called without an active exception
- identifier “string” undefined?
- Thread pooling in C++11
- Press Enter to Continue
- Converting a vector
to string - Parsing a comma-delimited std::string
- How can I convert const char* to string and then back to char*?
- std::string formatting like sprintf
- How does std::forward work? [duplicate]
- Sorting Characters Of A C++ String
- basic_string::_M_construct null not valid after constructing subvector of strings
- How to copy a string of std::string type in C++?
- How to return a string from a C++ function?
- std::out_of_range error?
- What is the difference between isdigit() and isnumber()?
- Convert char* to string C++
- Difference in make_shared and normal shared_ptr in C++
- printf with std::string?
- Convert a String In C++ To Upper Case
- What is std::move(), and when should it be used?
- Right way to split an std::string into a vector
- Read whole ASCII file into C++ std::string
- Right way to split an std::string into a vector
- string subscript out of range error
- C++ String Variable Declaration
- push_back vs emplace_back
- Returning an empty string : efficient way in c++
- Split a string into an array in C++
- splitting a string into an array in C++ without using vector
- Remove spaces from std::string in C++
- error: use of deleted function
- Remove spaces from std::string in C++
- c++ convert string to hex
- How can I iterate through a string and also know the index (current position)?
- c++ parse int from string [duplicate]
- Hash function for a string
- Call to implicitly deleted copy constructor in LLVM
- C++ strings and pointers
- cc1plus: error: unrecognized command line option “-std=c++11” with g++
- How to Convert a C++ String to Uppercase
- std::wstring VS std::string
- C++ Simple hangman game
- std::cin input with spaces?
- Remove First and Last Character C++