Created
September 28, 2023 01:05
-
-
Save esnosy/f95d99443b3749adfd6aafe39f132dbc to your computer and use it in GitHub Desktop.
A skip_line function for std::ifstream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void skip_line(std::ifstream &ifs) | |
{ | |
// Thanks to Eljay and CPPReference | |
// https://stackoverflow.com/questions/53693218/how-to-skip-a-line-of-standard-input#comment94242047_53693218 | |
// https://en.cppreference.com/w/cpp/string/basic_string/getline#Notes | |
// ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | |
// also thanks to https://stackoverflow.com/a/72365435/8094047 | |
// and https://jdhao.github.io/2018/12/08/newline_vim_python_sublime_notepad/ | |
// Skip all characters until newline or carriage return | |
char c = '\0'; | |
while (c != '\n' && c != '\r') { | |
ifs.get(c); | |
} | |
// Skip all whitespace | |
ifs >> std::ws; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment