There's no standard-library way to do it, but it's pretty easy to do, if I understand you correctly. If you want to read a string until some punctuation as though it were a newline, then you could use a version of getline
that accepts a predicate instead of a single delimiter:
template<class F>
std::istream& getline(std::istream& stream, std::string& string, F delim) {
string.clear();
// Get characters while the stream is valid and the next character is not the terminating delimiter.
while (stream && !delim(stream.peek()))
string += stream.get();
// Discard delimiter.
stream.ignore(1);
return stream;
};
Usage example:
#include <iostream>
#include <cctype>
int main(int argc, char** argv) {
std::string s;
getline(std::cin, s, ::ispunct);
std::cout << s << '\n';
return 0;
}
If you also want to break on newlines, then you can write a functor:
struct punct_or_newline {
bool operator()(char c) const { return ::ispunct(c) || c == '\n'; }
};
And invoke as getline(std::cin, my_string, punct_or_newline())
instead. Hope this helps!