C - Feof(stdin) - 如何表示Windows中的输入结束?

Ran*_*ien 2 c windows stdin eof

    int x,y,m;
for(;;){
    m=scanf("%d %d",&x,&y);
    if (m!=2 || m==EOF){
        break;
    }
    else{
        printf("/%d/%d/\n",x,y);
    }
}
if (feof ( stdin )){
  printf("End of input\n");
}else if(m!=2){
  printf("There was an error\n");
}
Run Code Online (Sandbox Code Playgroud)

在linux下ctrl + D表示输入结束,而对于windows ctrl + z应该可以做到这一点,但它不起作用.有任何想法吗?

ust*_*sta 5

按Ctrl + z后尝试按Enter键

如果仍然没有运气,请尝试C++版本:

#include <iostream>

int x, y;
while ( std::cin >> x >> y )
   std::cout << '/' << x << '/' << y << "/\n";
if ( std::cin.eof() )
   std::cout << "End of input\n";
else
   std::cout << "There was an error\n";
Run Code Online (Sandbox Code Playgroud)

看看它是否更好?