CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2006
    Posts
    144

    test.cpp:15: error: stray ‘\160’ in program

    Hello,

    when compiling sometimes I get the error above. I sense that it has to do with some character endcoding. It looks like it happens when I copy code I got via email into my source.

    Any idea?

    Cheers,
    J.

  2. #2
    Join Date
    Jan 2003
    Posts
    615

    Re: test.cpp:15: error: stray ‘\160’ in program

    How about showing us the code.

  3. #3
    Join Date
    Aug 2006
    Posts
    144

    Re: test.cpp:15: error: stray ‘\160’ in program

    It's the code someone else posted to a different question. I've copy and pasted it into an email, emailed that email to another computer and copy and pasted it back.




    #include<string>
    #include<iostream>
    #include<algorithm>

    using namespace std;

    char ChangeChar(char c)
    {
    if (c=='z' || c=='Z')
    return c-=25;
    else
    return ++c;
    }

    int main()
    {
    string mystring("HelloZ");
    cout << mystring << endl;
    std::transform(mystring.begin(), mystring.end(),mystring.begin(),ChangeChar);
    cout << mystring << endl;
    return 0;
    }

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: test.cpp:15: error: stray ‘\160’ in program

    Try the code in attached file, I have copied it into ANSI format.
    Attached Files Attached Files
    Regards,
    Ramkrishna Pawar

  5. #5
    Join Date
    Aug 2006
    Posts
    144

    Re: test.cpp:15: error: stray ‘\160’ in program

    No problem that one works fine.

    I have copied the original code into an email on MS Outlook and copied the source from Linux kmail into kate to save the source file and compile it.

    Your file I have donwloaded from linux directly.

  6. #6
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: test.cpp:15: error: stray ‘\160’ in program

    Quote Originally Posted by joebar
    No problem that one works fine.

    I have copied the original code into an email on MS Outlook and copied the source from Linux kmail into kate to save the source file and compile it.

    Your file I have donwloaded from linux directly.
    Cool !
    Regards,
    Ramkrishna Pawar

  7. #7
    Join Date
    Aug 2006
    Posts
    144

    Re: test.cpp:15: error: stray ‘\160’ in program

    yes cool, but what does it mean?

  8. #8
    Join Date
    Jan 2006
    Posts
    152

    Re: test.cpp:15: error: stray ‘\160’ in program


  9. #9
    Join Date
    Aug 2006
    Posts
    144

    Re: test.cpp:15: error: stray ‘\160’ in program

    The link doesn't help me - sorry.

    I acutally see the same source code in my text editor, what can I change in form of transmission to avoid that problem?

    I have to do it via email I can't set up any network route or whatsoever.

    Thanks.
    J.

  10. #10
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: test.cpp:15: error: stray ‘\160’ in program

    Quote Originally Posted by joebar
    yes cool, but what does it mean?
    I thought you said it works fine.
    Regards,
    Ramkrishna Pawar

  11. #11
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: test.cpp:15: error: stray ‘\160’ in program

    Quote Originally Posted by joebar
    I have to do it via email I can't set up any network route or whatsoever.
    Who is your email provider? Contact them regarding the problem with proper steps to reproduce (STR).

    Well, posting the STR here wouldn't harm either. I don't exactly understand your problem. Which email client are you using?

  12. #12
    Join Date
    Aug 2006
    Posts
    144

    Re: test.cpp:15: error: stray ‘\160’ in program

    Steps to reproduce:

    1. Copy and Paste coding from codeguru.com into Outlook 2003 email on Win XP
    2. Copy and Paste the coding received via email (kmail) into kate on Suse Linux 10.0.
    3. Save kate file as any name
    4. g++ -Wall file.cpp

    Sorry don't get me wrong but, No way to contact my email provider, the text is there in my email. I can read the text so why would my email provider "waste" his time? Do you know any email provider who would spend time on this?

    I only assume that it is due to character encoding, I can't think of anything else, but who knows.

    What does stray \160 mean?

  13. #13
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: test.cpp:15: error: stray ‘\160’ in program

    Okay, attach the same file here that creates the problem.

    I am not sure if I can help you (its hard to replicate the configuration that you have) but one issue that I can think of could be line-end issue. Whenever you move a file saved in windows to linux/unix - there is a well-known problem related to the line ends. A special Cntrl-M character appears in the file when opened on unix - you could view them using vim. Try using the dos2unix command for the file and try compiling.

    I will look further if I can help you - but don't rely on that.. have workarounds (I think you already have that). Regards.

  14. #14
    Join Date
    Aug 2006
    Posts
    144

    Re: test.cpp:15: error: stray ‘\160’ in program

    File which gives this problem is attached. Any help is appreciated.

    vi doesn't show any ^M, nor does a dos2unix command help.

    J.
    Attached Files Attached Files
    Last edited by joebar; September 5th, 2006 at 09:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured