stc
Loading...
Searching...
No Matches
StdFix.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <istream>
8#include <string>
9
10namespace stc::StdFix {
11
21inline std::istream& getline(std::istream& is, std::string& str) {
22 char ch;
23 str.clear();
24
25 while (!is.eof()) {
26 is.get(ch);
27 // Streams are weird with the null character. While this may seem like a redundant check,
28 // it avoids dupe characters.
29 if (is.eof()) break;
30 if (ch == '\r') {
31 if (!is.eof() && is.peek() == '\n') {
32 is.get(ch);
33 // We don't care whether the call above resulted in an EOF; we're exiting anyway, so it's all good
34 }
35 break;
36 } else if (ch == '\n') {
37 break;
38 }
39
40 str += ch;
41 }
42
43 return is;
44}
45
46}
Definition StdFix.hpp:10
std::istream & getline(std::istream &is, std::string &str)
Definition StdFix.hpp:21