代码之家  ›  专栏  ›  技术社区  ›  Maleev

如何去除文本文件中的特殊字符?(*尼克斯)

  •  1
  • Maleev  · 技术社区  · 15 年前

    我有一个源代码文件,它是从一个网页上的一些示例代码的副本开始的。 它是在Windows下创建和编辑的,编译时没有任何问题。

    但在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
    

    看起来问题出在一些特殊的角色身上。

    2 回复  |  直到 15 年前
        1
  •  9
  •   Williham Totland    15 年前

    在我看来,该文件似乎保存为UTF-16。在文本编辑器中打开它并重新编码到UTF-8,如果运气好的话,应该可以解决这个问题。

        2
  •  0
  •   Charlie    15 年前

    最初我只是想说如何删除\255&\254个字符,但我同意这些评论,它是unicode的。 尝试

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