通常の空白の代わりに \n に到達するまで、getline を使用せずにストリームにフォーマット オプションを保持せずに istream に続行するように指示する方法はありますか?
ありがとう。
何が問題なのstd::getline()
ですか? とにかく、あなた自身の関数を書くのはどうですか:
#include <iostream>
#include <iterator>
template<class In, class Out, class T>
Out copy_until(In first, In last, Out res, const T& val)
{
while( first != last && *first != val ) *res++ = *first++;
return res;
}
// ...
std::string line;
copy_until(std::istreambuf_iterator<char>(std::cin),
std::istreambuf_iterator<char>(),
std::back_inserter(line), '\n');
std::cout << line << std::endl;
関数は改行を消費しますが、出力には配置しません。