エラー:EOFはこの役割ドメインで宣言されていません

1184 ワード

追加する必要があります.
#include <cstdio>

---------------------------------------------------
C++Primer PlusのListing 5.19
// textin4.cpp -- reading chars with cin.get()
#include <iostream>  //   :#include <cstdio>
int main(void)
{
    using namespace std;
    int ch;                         // should be int, not char
    int count = 0;

    while ((ch = cin.get()) != EOF) // test for end-of-file
    {
        cout.put(char(ch));
        ++count;
    }
    cout << endl << count << " characters read
"; return 0; }
コンパイルエラー、わかりません:
textin4.cpp:    ‘int main()’ :
textin4.cpp:10:29:   : ‘EOF’          
でたらめに変更するしかありません.
/* Listing 5.19
 * textin4.cpp -- reading chars with cin.get() */
#include <iostream>
#ifndef EOF
#define EOF -1
#endif
int main (void)
{
	using namespace std;
	int ch; // should be int, not char
	int count = 0;
	
	while ((ch = cin.get()) != EOF) // test for end-of-file
	{
		cout.put(char(ch));
		++count;
	}
	cout << endl << count << " characters read
"; return 0; }
これでもちろんいいです.