I've noticed there were some questions similar, but I couldn't find the right answer.
I'd like to compare two strings - first given by the user, second written in the external .txt file. I almost wouldn't notice the problem because under Windows everything works just fine, condition in if is true for some certain values, but in Linux it isn't (it's compiling, but doesn't give proper results). I thought maybe cin is adding some extra characters under Linux (like \n etc.) but size() on both strings is the same value, as it should be.
What should I change?
string firststr, secondstr;
fstream dFile;
dFile.open("dfile.txt", ios::in);
if(dFile.good())
{
while (!dFile.eof())
{
dFile >> secondstr; //string from file
}
cin >> firststr;
if(firststr==secondstr) cout <<"OK!";
OK! is displayed under Windows, not under Linux.
I have also used getline(cin,firststr)
- without success.
I need to have a code working both under Windows (which I have already) and Linux.
I hope fact that both strings are members of some class doesn't change anything.
Thanks in advance for any solutions.