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?
- What is a lambda expression in C++11?
- How to convert string to char array in C++?
- ld: symbol(s) not found for architecture x86_64 error
- C++ string to double conversion
- What is `CString`?
- What is the ‘override’ keyword in C++ used for? [duplicate]
- What is a smart pointer and when should I use one?
- C++ std::priority_queue uses the lambda expression
- Usage and Syntax of std::function
- What exactly is nullptr?
- How to convert a char array to a string?
- Difference between `constexpr` and `const`
- How to convert an instance of std::string to lower case
- Check if a string contains a string in C++
- Replace part of a string with another string
- How to reverse an std::string? [duplicate]
- Compiling C++11 with g++
- std::string to char*
- What exactly is std::atomic?
- Issue with std::stol – ‘std::invalid_argument’ what(): stol
- How to convert a std::string to const char* or char*
- Cleanest way to copy a constant size array in c++11
- push_back vs emplace_back
- Why am I getting string does not name a type Error?
- What is move semantics?
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- C++ deprecated conversion from string constant to ‘char*’
- C++ terminate called without an active exception
- Press Enter to Continue
- Converting a vector
to string - Parsing a comma-delimited std::string
- std::string formatting like sprintf
- 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++
- printf with std::string?
- Convert a String In C++ To Upper Case
- Right way to split an std::string into a vector
- 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++
- error: use of deleted function
- 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
- cc1plus: error: unrecognized command line option “-std=c++11” with g++
- C++ Simple hangman game
- std::cin input with spaces?
- Remove First and Last Character C++
- Hash function for a string
- no match for ‘operator<<’ in ‘std::operator
- Dynamically allocated string array, then change it’s value?
- Use the auto keyword in C++ STL
- Fastest way to Convert String to Binary?
- Does C++11 have C#-style properties?
- Why I cannot cout a string?
- How to print a string in C++
- How do I create a random alpha-numeric string in C++?
- Trying to use int in getline
- error: switch quantity not an integer
- Reading a string from file c++
- When is it safe to call this-> in constructor and destructor
- How to change string into QString?
- How to memset char array with null terminating character?
- Remove last character from C++ string
- Converting String to Cstring in C++
- How well is Unicode supported in C++11?
- How to do std::string indexof in C++ that returns index of matching string?
- How to automatically convert strongly typed enum into int?
- Function stoi not declared
- Creating folders in C++
- Understanding error “terminate called after throwing an instance of ‘std::length_error’ what(): basic_string::_S_create Aborted (core dumped)”
- ‘setprecision’ is not a member of ‘std’
- Compiling C++11 with g++
- enum to string in modern C++11 / C++14 / C++17 and future C++20
- ERROR C2039: ‘vector’: is not a member of ‘std’
- Converting bool to text in C++
- c++ vector bubble sort
- Why are there two different getline() functions (if indeed there are)?
- Why does my program give “NULL used in arithmetic”
- How to find and replace string?
- How to use bitmask?
- Declaration is incompatible with type
- I’m getting the error “stoi is not a member of std” in myprogramminglab [duplicate]
- Differences between unique_ptr and shared_ptr