I'm having problems with std::getline on Mac OSX Snow Leopard. For some reason it limit the size of the input, while on Debian/Ubuntu it's unlimited size?
std::getline(std::cin, input)
Any clues about the limit?
I'm having problems with std::getline on Mac OSX Snow Leopard. For some reason it limit the size of the input, while on Debian/Ubuntu it's unlimited size?
std::getline(std::cin, input)
Any clues about the limit?
It is not the std::getline that differs between the platform (Windows/Unix/Mac OSX). It's how the line terminators are defined over different platforms. It is '\n\r' for Windows-based, '\n' for unix-based and ('\r'?) for MacOS platforms. Try generating your text file (or a test file) using a MacOS editor and examine if you still have a limit in the size of the input using std::getline?
The C++ standard says this about the getline
function:
21.3.7.9 Inserters and extractors [lib.string.io]
template<class charT, class traits, class Allocator>
basic_istream<charT,traits>&
getline(basic_istream<charT,traits>& is,
basic_string<charT,traits,Allocator>& str,
charT delim);
Effects: Begins by constructing a sentry object k
as if by basic_istream<charT,traits>::sentry k(is)
. If bool(k)
is true, it calls
str.erase()
and then extracts characters from is
and appends them to str
as if by calling
str.append(1,c)
until any of the following occurs:
getline
function calls
is.setstate(ios_base::eofbit)
).c == delim
for the next available input character c
(in which case, c
is extracted but not appended) (27.4.5.3)str.max_size()
characters are stored (in which case, the function calls is.setstate(ios_base::failbit)
) (27.4.5.3)So, the only reasons why you would be getting a short line are (a) your C++ implementation does not conform to the standard (highly unlikely), you're hitting end-of-file, or you're reading a 4 gigabyte line (highly unlikely).