1

When this line is not in a comment:

double random_seed, participation_fee, ticket_revenue;

the compiler produces the following errors:

main.cpp:24:2: error: stray ‘\200’ in program
main.cpp:24:2: error: stray ‘\254’ in program
main.cpp:24:2: error: stray ‘\342’ in program
main.cpp:24:2: error: stray ‘\200’ in program
main.cpp:24:2: error: stray ‘\254’ in program

I have already tried to retype this line. I am using Sublime Text as the text editor. How can I fix this problem?

This is the whole function:

void starting_game(vector<int>&players, vector<Player*> player_obj)
{
    int id, x, y, number=0;
    char pos;
    double random_seed,participation_fee,ticket_revenue;‬‬
    string input;
    cin >> number;
    for(int i = 0; i < number; i++)
    {
        cin >> id;
        cin.ignore(4,' ');
        cin >> x;
        cin.ignore(2,':');
        cin >> y;
        cin.ignore(2,':');
        cin >> pos;
        players.push_back(find_put(id, player_obj, x, y, pos));
    }
    //cin>>‫‪random_seed‬‬;//>>‫‪participation_fee‬‬>>‫‪ticket_revenue;‬‬
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
M.Davari
  • 43
  • 6
  • This is *not* a duplicate of the linked question. The characters in question are invisible (*POP DIRECTIONAL FORMATTING*, U+202c, ``"\342\200\254"`` in UTF-8), which makes this a lot harder to solve. – Jonas Schäfer Mar 18 '16 at 13:37
  • Welcome on StackOverflow. I have edited your post to make it more readable. To avoid getting downvotes in the future, please take more care when writing your post. Good language often helps with people taking your question seriously and answering it. – Jonas Schäfer Mar 18 '16 at 13:41
  • Copy & paste whole content into a plain text editor, then back. – zdf Mar 18 '16 at 13:53
  • This ***is*** a FAQ. The real canonical question is *[Compilation error: stray ‘\302’ in program, etc](https://stackoverflow.com/questions/19198332)*. All questions of this type can be analysed in exactly the same way: The sequence of numbers are (usually) octal. Convert them to hexadecimal and search for the UTF-8 sequence to find the Unicode [code point](https://en.wikipedia.org/wiki/Code_point). It can be searched directly (and replaced) by using regular expression search (using `\x{Unicodepoint}`) in text editors capable of search with regular expressions. – Peter Mortensen Aug 03 '21 at 22:50

1 Answers1

2

You have invisible characters inside your code which stop the compiler from working correctly, because it cannot deal with them.

In your specific case, one of those characters is U+202c, encoded using UTF-8. It is called "POP DIRECTIONAL FORMATTING", and invisible.

Being invisible, fixing this will be hard. Even the code in the question contains that character.

To fix it, you can do some of the following:

  • Try deleting the whole line, as well as the next line, and retype the text. In your specific case, the characters linger at the end of the line and might be preserved if you simply erase the contents line and retype it, without also killing the linebreak. (via @PatrickTrentin)

  • Use a script which removes all non-ascii characters. This is easily done with python. Paste the following code in a text file called script.py and execute it using python3.

    #!/usr/bin/python3
    import argparse
    import sys
    
    parser = argparse.ArgumentParser()
    
    parser.add_argument("infile", type=argparse.FileType("rb"))
    parser.add_argument("outfile", type=argparse.FileType("wb"))
    
    args = parser.parse_args()
    
    with args.infile as inf:
       intext = inf.read().decode("utf-8")
       with args.outfile as outf:
          outf.write("".join(
              c for c in intext
              if ord(c) <= 127
          ).encode("utf-8"))
    

    Usage is python3 script.py input output. Do not enter the same name twice, it will not work and you will end up with an empty file. In any case, make a backup of your files before trying this!

  • Use a hex editor to manually get rid of all non-ASCII characters. Unfortunately, I do not know anyone which is easy to use.

In this case, removing the characters without replacement is the right thing to do. In other cases (such as the proposed duplicate), it is more correct to replace the offending characters with something more appropriate. This is not the case here.

Community
  • 1
  • 1
Jonas Schäfer
  • 20,140
  • 5
  • 55
  • 69
  • 1
    The solution is as simple as rewriting `double random_seed, participation_fee, ticket_revenue;` manually, and deleting the whole line with the ominous hidden codes, using for example `ctrl+k` in nano.. [eta: i didn't downvote] – Patrick Trentin Mar 18 '16 at 13:51
  • @PatrickTrentin According to the OP, this did not help. This might be due to the codes being actually at the line ending, depending on the editor. Considering that other commented-out lines have the same problem, an automated solution seemed applicable ☺ – Jonas Schäfer Mar 18 '16 at 14:10
  • 1
    right, the trick is to use editors that allow for deleting the whole line at once e.g. `nano, vim, etc..`. I tried it myself on his code. I think yours is a good answer actually, just wanted to point out the simplest path. :) – Patrick Trentin Mar 18 '16 at 14:15