So I just noticed something weird about opening .txt files in sublime that were created in vim.
It seems sublime adds an empty line at the end of the .txt file. For example, if I use vim/gedit to type the following 2 line file:
1
2
When I open this .txt file in Sublime, it opens as
1
2
~
where I have used "~" to represent an empty line. Could someone try this and tell me if it's the same for you?
This is the code I was using that doesn't seem to work when I create the .txt file in sublime:
#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);
}
The expected output is:
Read a: 1
Read b: 2
Sum: 3
But if you create the inputVals.txt file in Sublime, you obtain:
Read a: 1
EOF before reading b