Your premise is wrong: std::getline
does work with std::string
:
template< class CharT, class Traits, class Allocator >
std::basic_istream<CharT,Traits>& getline( std::basic_istream<CharT,Traits>& input,
std::basic_string<CharT,Traits,Allocator>& str,
CharT delim );
This means you can read from std::cin
to an std::string
until a given delimiter:
std::string destination;
std::getline(std::cin, destination, '|');
('|'
taken as an exemple delimiter)
Note: you should check getline
's return before reading from destination
. getline
returns a reference to std::cin
which can be converted to a bool
whose value is true
if the stream is in a correct state:
if (std::getline(std::cin, destination, '|') == false) {
// error handling
}