所以我注意到在vim中创建的sublime中打开.txt文件时有些奇怪。
似乎sublime在.txt文件的末尾添加了一个空行。例如,如果我使用vim / gedit键入以下2行文件:
1
2
~
当我在Sublime中打开此.txt文件时,它将以
打开#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main()
{
int a;
int b;
ifstream inFile;
bool validInputFound;
inFile.open("inputVals.txt");
if (inFile.fail())
{
cout << "Unable to open input file!" << endl;
exit(1);
}
validInputFound = false;
while (!validInputFound)
{
inFile >> a;
if (inFile.eof())
{
cout << "EOF before reading a" << endl;
exit(2);
}
else if (inFile.fail())
{
inFile.clear();
inFile.ignore(200, '\n');
}
else
{
validInputFound = true;
}
}
cout << "Read a: " << a << endl;
validInputFound = false;
while (!validInputFound)
{
inFile >> b;
if (inFile.eof())
{
cout << "EOF before reading b" << endl;
exit(2);
}
else if (inFile.fail())
{
inFile.clear();
inFile.ignore(200, '\n');
}
else
{
validInputFound = true;
}
}
cout << "Read b: " << b << endl;
cout << "Sum: " << a + b << endl;
inFile.close();
return (0);
}
我用“〜”表示空行。有人试试这个并告诉我你是否也一样?
当我在sublime中创建.txt文件时,这是我使用的代码似乎不起作用:
Read a: 1
Read b: 2
Sum: 3
预期输出为:
Read a: 1
EOF before reading b
但是如果你在Sublime中创建inputVals.txt文件,你将获得:
{{1}}
答案 0 :(得分:0)
看起来vim添加换行符而不是Sublime Text。