2009-07-13 11 views
1

私は、Webページからいくつかのサンプルコードのコピーとして始まったソースコードファイルを持っています。 Windowsで作成および編集され、問題なくコンパイルされました。テキストファイル内の特殊文字を取り除く方法は? (* nix)

しかし、Macの下、私はのような、あいまいなエラーの負荷を取得する:問題は一部の特殊文字であるように

../MyProgram.cpp:1: error: stray '\255' in program 
../MyProgram.cpp:1: error: stray '\254' in program 
../MyProgram.cpp:1: error: stray '#' in program 
../MyProgram.cpp:3:4: error: invalid preprocessing directive #i 
../MyProgram.cpp:5:4: error: invalid preprocessing directive #i 
../MyProgram.cpp:7:4: error: invalid preprocessing directive #i 
../MyProgram.cpp:23: error: missing terminating ' character 
../MyProgram.cpp:369:6: error: invalid preprocessing directive #i 
../MyProgram.cpp:371:8: error: invalid preprocessing directive #i 
../MyProgram.cpp:375:8: error: invalid preprocessing directive #e 
../MyProgram.cpp:381:8: error: invalid preprocessing directive #e 
../MyProgram.cpp:383:6: error: invalid preprocessing directive #e 
../MyProgram.cpp:385:8: error: invalid preprocessing directive #i 
../MyProgram.cpp:389:8: error: invalid preprocessing directive #e 
../MyProgram.cpp:1: error: 'i' does not name a type 
../MyProgram.cpp:53: error: 'V' does not name a type 
../MyProgram.cpp:75: error: 'v' does not name a type 
../MyProgram.cpp:157: error: 'l' does not name a type 
../MyProgram.cpp:169: error: 'l' does not name a type 
../MyProgram.cpp:187: error: 'i' does not name a type 
../MyProgram.cpp:197: error: 'v' does not name a type 

が見えます。

どうすれば* nixコマンドラインでそれらを削除できますか?

+0

UNIXの多くのディストリビューションでは、/ usr/binにあるdos2unixユーティリティがあります。 OSXにはそれがありません。 – Alex

+0

http://dos2unix.darwinports.com/ – Jon

+2

この問題は特殊文字ではありません。それはUTF-16です:あなたのヒントはFFFEです。 –

答えて

9

ファイルがUTF-16として保存されているかのように見えます。それをテキストエディタで開き、UTF-8に再エンコーディングすると、問題が解決するはずです。

+0

あなたは正しいです、それはUTF-16です、今修正されました – Maleev

0

元私は\ 255 & \ 254文字を削除する方法を説明していましたが、コメントに同意します。これはユニコードです。 try

iconv -f iso-8859-1 -t utf-8 infile > outfile 

iso-8859-1 is just a推測です。

関連する問題