Defined in header <cparse/Cursor.hh>
stream_type::char_type get();
Consumes the next character from the underlying stream, updates the line and column counters, and returns the character.
Line and column tracking: if the previous character was a newline, the line counter is incremented and the column counter is reset to one. Otherwise the column counter is incremented. The very first get() call after construction moves the position from "before any character" (line 0, column 0) to "at the first character" (line 1, column 1).
Parameters
None.
Return value
The character that was consumed, as stream_type::char_type (a signed char). No sentinel is returned on end-of-input — a throw occurs instead.
Exceptions
- Throws
std::runtime_errorwith the message[Cursor::get] invalid streamif the internal stream pointer is null. - Throws
std::ios_base::failureif the stream signalsfailbit,eofbitorbadbit, per the exception mask set by the constructors. End-of-input arrives via this path — the exception is whatParser::parse()catches to detect clean or truncated EOF.
Notes
Use safeGet() inside your own consuming loops so that end-of-input does not throw out of them; use get() when you have already peeked and know a character is available, or when you deliberately want the EOF exception to propagate.
Example
#include <cparse/Cursor.hh>
#include <sstream>
#include <iostream>
int main()
{
auto ss = std::make_shared<std::istringstream>("hi");
fedem::parser::Cursor c("<memory>", ss);
try
{
while (true) std::cout << c.get();
}
catch (std::ios_base::failure const&)
{
std::cout << "\n[reached EOF]\n";
}
}
Output:
hi
[reached EOF]
See also
- Cursor::safeGet — non-throwing variant.
- Cursor::peek — inspect without consuming.

