Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 怪异的EOF行为C++/VIM与其他IDE_C++_Vim_Eof - Fatal编程技术网

C++ 怪异的EOF行为C++/VIM与其他IDE

C++ 怪异的EOF行为C++/VIM与其他IDE,c++,vim,eof,C++,Vim,Eof,我目前在使用我的程序正确设置EOF位时遇到问题。 这个程序的要求是,我将有两个文件,都有整数的排序列表。程序应该从两个文件中提取一个数字,然后比较这些数字。如果一个比另一个小,则较小的一个将输出到另一个文件中,然后从该文件中提取另一个编号,该编号是从该文件获取其原始编号的 举个例子,让我们假设文件1中有一个整数1 3 5 9,在整数之间有一条新行,而不是一个空格,文件2中有2 4 6 10。应将1与2进行比较,然后将1绘制到输出文件中。1将被数字3替换 为了帮助我解决这个问题,我研究了在最后一个

我目前在使用我的程序正确设置EOF位时遇到问题。 这个程序的要求是,我将有两个文件,都有整数的排序列表。程序应该从两个文件中提取一个数字,然后比较这些数字。如果一个比另一个小,则较小的一个将输出到另一个文件中,然后从该文件中提取另一个编号,该编号是从该文件获取其原始编号的

举个例子,让我们假设文件1中有一个整数1 3 5 9,在整数之间有一条新行,而不是一个空格,文件2中有2 4 6 10。应将1与2进行比较,然后将1绘制到输出文件中。1将被数字3替换

为了帮助我解决这个问题,我研究了在最后一个数字被绘制之后,在尝试再次绘制一个数字之后设置EOF标志。这在我下面的代码中非常有效,其中包含通过VIM创建的输入文件。文件1中的最后一个数字被写入输出文件后,设置EOF位,然后程序从第二个文件中引入所有数字

但是,如果我在任何IDE或文本编辑器中使用相同数量的字符间新闻空间编写相同的输入文件,我会看到一些奇怪的EOF行为。当我在Sublime Text2或Text Edit中写入相同的文件时,在绘制最后一个数字时,EOF位设置正确。假设我们使用命令inputFile2>>number2,当该命令绘制最后的数字10时,EOF将设置为1。在通过VIM创建的文本文件中,如果我们使用命令inputFile2>>number2,最后一个数字被绘制为10,那么在我运行命令inputFile2>>number2之前,EOF不会设置为1

有人知道为什么两位编辑之间会有差异吗?我在下面提供了代码。有人知道可能出了什么问题吗?谢谢你的帮助

std::ifstream inputFile;
std::ifstream inputFile2;
std::ofstream outputFile;
bool conditionMet = false;

/* string variables for user input for files */
std::string inputName;
std::string inputName2;
std::string outputName;

/* int variables to hold the input from file */

int number1,
    number2;


inputFile.open("num1.txt");
inputFile2.open("num2.txt");
outputFile.open("output.txt);

inputFile >> number1;
inputFile2 >> number2;

/* loop until all of the numbers from files are in */
while (conditionMet == false)
{

    /* if the first number is less than or equal to the second number */
    /* check if the input file for number one is at the end of file */
    if (number1 <= number2)
    {

        /* if the end of file has been reached for the input file 1 */
        if (inputFile.eof())
        {
            /* put all of the numbers from input file 2 until the end of file for the second file */
            while (!inputFile2.eof())
            {

                outputFile << number2 << '\n';
                inputFile2 >> number2;
            }

            /* end the loop */

            conditionMet = true;

        }

        /* if the end of the file has not been reached then output number from input file 1 and then take in a new number */
        else if (!inputFile.eof())
        {
            std::cout << inputFile.eof() << "file1 eof before" << number1 << std::endl;
            outputFile << number1 << '\n';

            inputFile >> number1;
            std::cout << inputFile.eof() << "file1 eof after" << number1 << std::endl;
        }
    }

    /* if the first number is greater than the second number */

    else if (number1 > number2)
    {

        /* check if the input file for number two is at the end of file */
        /* if the end of file has been reached for the input file 2 */
        if (inputFile2.eof())
        {
            /* put all of the numbers from input file  until the end of file for the first file */
            while (!inputFile.eof())
            {
                outputFile << number1 << '\n';
                inputFile >> number1;
            }

            /* end the loop */
            conditionMet = true;

        }


    /* if the end of the file has not been reached, then output number from input file 2 and then take in a new number */

        else if (!inputFile2.eof())
        {
            std::cout << inputFile2.eof() << "file2 eof before" << number2 << std::endl;
            outputFile << number2 << '\n';

            inputFile2 >> number2;
            std::cout << inputFile2.eof() << "file2 eof after" << number2 << std::endl;
        }



    }



}

/* close all files */
inputFile.close();
inputFile2.close();
outputFile.close();

return 0;
std::ifstream输入文件;
std::ifstream inputFile2;
std::of流输出文件;
bool conditionMet=false;
/*用于用户输入文件的字符串变量*/
std::字符串inputName;
std::字符串inputName2;
std::string outputName;
/*int变量来保存文件中的输入*/
整数1,
2号;
open(“num1.txt”);
inputFile2.open(“num2.txt”);
outputFile.open(“output.txt”);
输入文件>>编号1;
输入文件2>>编号2;
/*循环,直到文件中的所有数字都在*/
while(conditionMet==false)
{
/*如果第一个数字小于或等于第二个数字*/
/*检查数字1的输入文件是否位于文件末尾*/

如果(number1这是因为
VIM
(我的配置也包括
emacs
)总是以换行结束文件。之所以这样做,是因为VIM是面向行的,对于C/C++源代码,这确实是标准要求的

事实上,
VIM
对于可能由相对较短的行组成的长文件来说确实非常专业,可以通过尝试使用由一行组成的10Mb文件(不要这样做)来看出这一点