#include#include int main() { std::istringstream ss("hello|world"); std::string s1, s2; std::getline(ss, s1, '|'); // Extract "hello" up to "|" ss.ignore(); // Ignore the delimiter "|" std::getline(ss, s2); // Extract "world" std::cout << s1 << " " << s2 << std::endl; // Prints "hello world" return 0; }
#includeIn this example, we create a stringstream `ss` with the input string "hello world". We then use `ss.ignore(5)` to skip the first 5 characters (i.e. "hello "). Finally, we use `ss.get(c)` in a loop to extract and print the rest of the string " world". The `istream::ignore` function is part of the C++ standard library, which is included in the `#include int main() { std::istringstream ss("hello world"); ss.ignore(5); // Ignore the first 5 characters char c; while (ss.get(c)) { std::cout << c; // Prints " world" } return 0; }