标题:请问C++中EOF怎么结束?已经连续按了ctrl+z了
只看楼主
paramous
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-19
 问题点数:0 回复次数:0 
请问C++中EOF怎么结束?已经连续按了ctrl+z了
今天我编了个计算文章行数、字符数的程序,里面的do while 循环要用EOF结束。可是运行后我按了CTRL+Z、CTRL+D等全部组合键都不能结束。
#include <iostream>
using namespace std;
int main()
{
    int word,line,ch,isword=0;
    char c;
    do{
        c=cin.get();
        if(c=='\n') line++;
        if(c!='\n'&&c!='t'&&c!=' ')
        {
            ch++;
            if(isword==0) word++;
        }
        isword=1;
    }while(c!=EOF);
        cout<<"line="<<line<<endl;
        cout<<"word="<<word<<endl;
        cout<<"ch="<<ch<<endl;
        return 0;

}#include <iostream>
using namespace std;
int main()
{
    int word,line,ch,isword=0;
    char c;
    do{
        c=cin.get();
        if(c=='\n') line++;
        if(c!='\n'&&c!='t'&&c!=' ')
        {
            ch++;
            if(isword==0) word++;
        }
        isword=1;
    }while(c!=EOF);
        cout<<"line="<<line<<endl;
        cout<<"word="<<word<<endl;
        cout<<"ch="<<ch<<endl;
        return 0;

}

这是我连续按了几个CTRL+Z的情景  PS:我是在虚拟机里面做的,不知道又没有影响。
搜索更多相关主题的帖子: 组合键 文章 include word 
2012-08-19 16:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-379768-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.110969 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved