Skip to content

Commit fde1357

Browse files
committed
Changed the C EOF constant to the C++ EOF constant function.
1 parent 7a93396 commit fde1357

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

cpp/AdaptiveArithmeticCompress.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <fstream>
1919
#include <iostream>
2020
#include <stdexcept>
21+
#include <string>
2122
#include "ArithmeticCoder.hpp"
2223
#include "BitIoStream.hpp"
2324
#include "FrequencyTable.hpp"
@@ -45,7 +46,7 @@ int main(int argc, char *argv[]) {
4546
while (true) {
4647
// Read and encode one byte
4748
int symbol = in.get();
48-
if (symbol == EOF)
49+
if (symbol == std::char_traits<char>::eof())
4950
break;
5051
if (!(0 <= symbol && symbol <= 255))
5152
throw std::logic_error("Assertion error");

cpp/ArithmeticCompress.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <fstream>
1818
#include <iostream>
1919
#include <stdexcept>
20+
#include <string>
2021
#include <vector>
2122
#include "ArithmeticCoder.hpp"
2223
#include "BitIoStream.hpp"
@@ -40,7 +41,7 @@ int main(int argc, char *argv[]) {
4041
freqs.increment(256); // EOF symbol gets a frequency of 1
4142
while (true) {
4243
int b = in.get();
43-
if (b == EOF)
44+
if (b == std::char_traits<char>::eof())
4445
break;
4546
if (b < 0 || b > 255)
4647
throw std::logic_error("Assertion error");
@@ -65,7 +66,7 @@ int main(int argc, char *argv[]) {
6566
while (true) {
6667
// Read and encode one byte
6768
int symbol = in.get();
68-
if (symbol == EOF)
69+
if (symbol == std::char_traits<char>::eof())
6970
break;
7071
if (!(0 <= symbol && symbol <= 255))
7172
throw std::logic_error("Assertion error");

cpp/BitIoStream.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <limits>
1010
#include <stdexcept>
11+
#include <string>
1112
#include "BitIoStream.hpp"
1213

1314

@@ -18,11 +19,11 @@ BitInputStream::BitInputStream(std::istream &in) :
1819

1920

2021
int BitInputStream::read() {
21-
if (currentByte == EOF)
22+
if (currentByte == std::char_traits<char>::eof())
2223
return -1;
2324
if (numBitsRemaining == 0) {
2425
currentByte = input.get(); // Note: istream.get() returns int, not char
25-
if (currentByte == EOF)
26+
if (currentByte == std::char_traits<char>::eof())
2627
return -1;
2728
if (!(0 <= currentByte && currentByte <= 255))
2829
throw std::logic_error("Assertion error");

cpp/PpmCompress.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <fstream>
1818
#include <iostream>
1919
#include <stdexcept>
20+
#include <string>
2021
#include <vector>
2122
#include "ArithmeticCoder.hpp"
2223
#include "BitIoStream.hpp"
@@ -69,7 +70,7 @@ static void compress(std::ifstream &in, BitOutputStream &out) {
6970
while (true) {
7071
// Read and encode one byte
7172
int symbol = in.get();
72-
if (symbol == EOF)
73+
if (symbol == std::char_traits<char>::eof())
7374
break;
7475
if (!(0 <= symbol && symbol <= 255))
7576
throw std::logic_error("Assertion error");

0 commit comments

Comments
 (0)