Или лыжи не едут или ... других вариантов нет :)
читаю C++ Standard Library, The: A Tutorial and Reference Nicolai M. Josuttis
Там в разделе про string написано
[Цитата]
istream& getline (istream& strm, string& str)
istream& getline (istream& strm, string& str, char delim)
Read the characters of the next line from strm into the string str.
All characters (including leading whitespaces) are extracted until any of the following happens:
* strm. width() is greater than 0 and width() characters are sored
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* strm.good() is false (which might cause an appropriate exception)
* delim or strm. widen('\n') is extracted
* str.max_size() characters are stored
[/Цитата]
Ага.. пишу:
std::ifstream in("file.txt");
while(!in.eof())
{
string s;
in.width(2);
if(std::getline(in,s))
std::cout<<s<<std::endl;
else
break;
}
и вместо того чтобы читать в s по 2 символа, getline все равно читает пока не встретит конец строки или eof.
Что такое? в книге ошибка или у меня getline неправильный?
gcc version 3.4.2 (mingw-special).