Warning: file_get_contents() [function.file-get-contents]: SSL: 远程主机强迫关闭了一个现有的连接。 in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884

Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
被scanf坑了,长个记性 - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


要求:获取不定长的输入,含有空格和回车。


如果直接编译出来cmd运行,这个程序一直结束不了,因为是不定长输入,也不知道什么时候该结束。但是如果是提交到OI测评的时候,输入数据尾部其实有EOF,所以是可以结束的。


我不知道这个,把我可害了。


所以最后写成了这样:

    string strCode;    // 输入内容

    // 读取输入
    while (true)
    {
        char strLine[1024] = { 0 };    // 每行的输入
        gets(strLine);
        char c;
        int r = scanf("%c", &c);
        strCode += strLine;

        if (r == EOF)
        {
            break;
        }
        else
        {
            strCode += "\n";
            strCode += c;
        }
    }

哎呀,惨不忍睹。


简化:

    // 读取整段代码
    char c;
    string strCode;    // 存储输入
    while (scanf("%c",&c) != EOF)
        strCode+=c;




返回首页


Copyright (C) 2018-2024 huidong