M-BM-

今天拷贝了一段代码

struct    Test   
   {   
           Test(    int    )    {}   
           Test()    {}   
           void    fun()    {}   
   };   
   void    main(    void    )   
   {   
           Test    a(1);   
           a.fun();   
           Test    b();   
           b.fun();   
   }   

编译的时候报错

01.cpp:16:1: error: stray ‘\240’ in program
01.cpp:16:1: error: stray ‘\302’ in program
01.cpp:16:1: error: stray ‘\240’ in program
01.cpp:16:1: error: stray ‘\302’ in program
01.cpp:16:1: error: stray ‘\240’ in program
01.cpp: In function ‘int main()’:
01.cpp:14:4: error: request for member ‘fun’ in ‘b’, which is of non-class type ‘Test()’
  b.fun();   

显然是字符的问题,

[root@ba face]# cat -v 01.cpp 
#include <stdio.h>
struct TestM-BM- M-BM- M-BM- 
{M-BM- M-BM- M-BM- 
	Test(int){}M-BM- M-BM- M-BM- 
	Test(){}M-BM- M-BM- M-BM- 
	void fun(){}M-BM- M-BM- M-BM- 
};M-BM- M-BM- M-BM- 

intM-BM- main(void)M-BM- M-BM- M-BM- 
{M-BM- M-BM- M-BM- 
	TestM-BM- a(1);M-BM- M-BM- M-BM- 
	a.fun();M-BM- M-BM- M-BM- 
	TestM-BM- b();M-BM- M-BM- M-BM- 
	b.fun();M-BM- M-BM- M-BM- 
	return 0;
}M-BM- M-BM- M-BM-

猜想M-BM-是Linux下的一个特殊字符,要怎么替换呢,想到用十六进制方式替换,那么首先查看这个特殊字符的十六进制表示,用od命令

[root@ba face]# od -tcx1 01.cpp
000000   #   i   n   c   l   u   d   e       <   s   t   d   i   o   .
       23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e
000010   h   >  \n  \n   s   t   r   u   c   t       T   e   s   t 302
       68 3e 0a 0a 73 74 72 75 63 74 20 54 65 73 74 c2
000020 240 302 240 302 240  \n   { 302 240 302 240 302 240  \n   T   e
       a0 c2 a0 c2 a0 0a 7b c2 a0 c2 a0 c2 a0 0a 54 65
000030   s   t   (   i   n   t   )   {   } 302 240 302 240 302 240  \n
       73 74 28 69 6e 74 29 7b 7d c2 a0 c2 a0 c2 a0 0a
000040   T   e   s   t   (   )   {   } 302 240 302 240 302 240  \n   v
       54 65 73 74 28 29 7b 7d c2 a0 c2 a0 c2 a0 0a 76
000050   o   i   d 302 240   f   u   n   (   )   {   } 302 240 302 240
       6f 69 64 c2 a0 66 75 6e 28 29 7b 7d c2 a0 c2 a0
000060 302 240  \n   }   ; 302 240 302 240 302 240  \n   v   o   i   d
       c2 a0 0a 7d 3b c2 a0 c2 a0 c2 a0 0a 76 6f 69 64
000070 302 240   m   a   i   n   (   v   o   i   d   ) 302 240 302 240
       c2 a0 6d 61 69 6e 28 76 6f 69 64 29 c2 a0 c2 a0
000080 302 240  \n   { 302 240 302 240 302 240  \n   T   e   s   t 302
       c2 a0 0a 7b c2 a0 c2 a0 c2 a0 0a 54 65 73 74 c2
000090 240   a   (   1   )   ; 302 240 302 240 302 240  \n   a   .   f
       a0 61 28 31 29 3b c2 a0 c2 a0 c2 a0 0a 61 2e 66
0000a0   u   n   (   )   ; 302 240 302 240 302 240  \n   T   e   s   t
       75 6e 28 29 3b c2 a0 c2 a0 c2 a0 0a 54 65 73 74
0000b0 302 240   b   (   )   ; 302 240 302 240 302 240  \n   b   .   f
       c2 a0 62 28 29 3b c2 a0 c2 a0 c2 a0 0a 62 2e 66
0000c0   u   n   (   )   ; 302 240 302 240 302 240  \n   } 302 240  \n
       75 6e 28 29 3b c2 a0 c2 a0 c2 a0 0a 7d c2 a0 0a
0000d0

可以看到这个特殊字符的十六进制表示是c2 a0,,用如下命令替换即可

[root@ba face]# sed -i 's/\xc2\xa0//g' 01.cpp 
[root@ba face]# cat -v 01.cpp 
#include <stdio.h>
struct Test   
{   
	Test(int){}   
	Test(){}   
	void fun(){}   
};   

int main(void)   
{   
	Test a(1);   
	a.fun();   
	Test b();   
	b.fun();   
	return 0;
}   
[root@ba face]# g++ 01.cpp 
01.cpp: In function ‘int main()’:
01.cpp:14:4: error: request for member ‘fun’ in ‘b’, which is of non-class type ‘Test()’
  b.fun();  

 

posted @ 2016-07-08 10:05  Geeken  阅读(1431)  评论(0编辑  收藏  举报