[Solved] My codes work well In Dev c++ IDE, but in linux terminal, it doesn’t. (especially in the part of ‘while’ loop.) [closed]


You are most likely running into the NL/CR issue.

Instead of

if (a[i]=="")

Use something like:

if (isEmptyLine(a[i]))

where

bool isEmptyLine(std::string const& s)
{
   for ( auto c : s )
   {
      if ( !std::isspace(c) )
        return false;
   }
   return true;
}

You can also convert the file into a file with UNIX style line endings by using a utility called dos2unix. That should also fix the problem.

solved My codes work well In Dev c++ IDE, but in linux terminal, it doesn’t. (especially in the part of ‘while’ loop.) [closed]