Stray '\342' in C++ program

后端 未结 4 458
小蘑菇
小蘑菇 2020-12-10 02:47

I\'m getting these errors in my program after pasting in some code:

showdata.cpp:66: error: stray ‘\\342’ in program         


        
相关标签:
4条回答
  • 2020-12-10 02:53

    The symbol is not ". Those are called 'smart quotes' and are usually found in rich documents or blogs.

    0 讨论(0)
  • 2020-12-10 02:58

    The lines

     size_t startpos = str.find_first_not_of(” \t”); 
     size_t endpos = str.find_last_not_of(” \t”); 
    

    have some "special" kind of double quotes, try the following:

     size_t startpos = str.find_first_not_of(" \t"); 
     size_t endpos = str.find_last_not_of(" \t"); 
    
    0 讨论(0)
  • 2020-12-10 03:05

    It is worth mentioning here (for whoever lands on this page just like me) that this sort of error message error: stray ‘\xyz’ in program can appear with any other character or symbol that is not recognized by the compiler as a legal one.

    Sharing my personal experience:

     - bool less<const char∗>(const char∗ a, const char∗ b)  
     - bool less<const char*>(const char* a, const char* b)   
    

    Former one is copy-pasted from a PDF file. It doesn't compile..

    Later one compiles as expected.

    0 讨论(0)
  • 2020-12-10 03:06

    You can use the sed command to fix these issues.

    This will give you a quick preview of what will be replaced.

    sed s/[”“]/'"'/g File.txt

    This will do the replacements and put the replacement in a new file called WithoutSmartQuotes.txt.

    sed s/[”“]/'"'/g File.txt > WithoutSmartQuotes.txt

    This will overwrite the original file.

    sed -i ".bk" s/[”“]/'"'/g File.txt

    0 讨论(0)
提交回复
热议问题