[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Script polluted by DOS formatting



On Fri, 13 Jul 2007 22:44:38 +0200
Christian Holm Christensen <cholm@nbi.dk> wrote:
> 
> Why not write a small C++ program that does what you want: 
> 
> 	#include <iostream> 
> 	int main() 
> 	{
> 	   while (!std::cin.eof()) { 
> 	      char c = std::cin.get();
> 	      if (std::cin.fail()) break;
> 	      if (c == 0302 || c == 0240) continue;
> 	      std::cout.put(c);
>            }
>            return 0;
>         } 
...

I realise this isn't a C++ forum, but that won't work as char on its
own is signed, so would never get big enough (c \in (-127,127]).

This works though, I think:

#include <iostream> 

int main(int argc, char** argv) 
{
  using std::cin; using std::cout;
  unsigned char c;

  while(1) {
    c = cin.get();

    if( cin.fail() ) break;

    if (c == 0302 || c == 0240)
      continue;

    cout.put(c);
  }
  return 0;
}

Attachment: signature.asc
Description: PGP signature


Reply to: