zoukankan      html  css  js  c++  java
  • 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   >  
      
       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  
       { 302 240 302 240 302 240  
       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  
    
           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  
       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  
       }   ; 302 240 302 240 302 240  
       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  
       { 302 240 302 240 302 240  
       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  
       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  
       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  
       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  
       } 302 240  
    
           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/xc2xa0//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();  
    
  • 相关阅读:
    在命令行下运行Matlab
    VMWare无法共享文件夹(Win7宿主机Ubuntu14.04客户机)
    [转] CVonline: Image Databases
    第二天
    第一天
    二宝软件的NABCD分析
    用c++实现环形数组的最大子数组之和
    返回一个二维整数数组中最大子数组的和
    求最大子数组之和
    四则运算
  • 原文地址:https://www.cnblogs.com/seeken/p/5652403.html
Copyright © 2011-2022 走看看