声明变量时编译器错误 - 八进制序列 200 254 342
Compiler error when declaring a variable - octal sequence 200 254 342
当此行不在注释中时:
double random_seed, participation_fee, ticket_revenue;
编译器生成以下错误:
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
我已经尝试重新输入此行。我正在使用崇高文本作为文本编辑器。如何解决此问题?
这是整个函数:
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;
}
代码中有不可见的字符,这会阻止编译器正常工作,因为它无法处理它们。
在您的特定情况下,其中一个字符是 U+202c,使用 UTF-8 编码。它被称为"POP定向格式",并且不可见。
由于是隐形的,解决这个问题将很困难。甚至问题中的代码也包含该字符。
要修复它,您可以执行以下操作:
-
尝试删除整行以及下一行,然后重新键入文本。在您的特定情况下,字符徘徊在行尾,如果您只是擦除内容行并重新键入它,而不会同时杀死换行符,则可能会保留这些字符。(通过@PatrickTrentin)
-
使用删除所有非 ASCII 字符的脚本。这很容易用python完成。将以下代码粘贴到名为
script.py
的文本文件中,并使用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"))
用法
python3 script.py input output
。不要两次输入相同的名称,它不起作用,你最终会得到一个空文件。无论如何,请在尝试此操作之前备份您的文件! -
使用十六进制编辑器手动删除所有非 ASCII 字符。不幸的是,我不知道任何易于使用的人。
在这种情况下,删除字符而不替换是正确的做法。在其他情况下(例如建议的副本),用更合适的字符替换有问题的字符更正确。这里的情况并非如此。
相关文章:
- 用c++把小数点转换成八进制
- 如何使用 SML 随机生成八进制元组
- 编译器始终打印十六进制/八进制数字
- 在 C++ 中使用带有十六进制十进制和八进制数的 unsetf
- 十进制到八进制递归C++.以标准::字符串格式输出
- 在C++中,将无符号整数转换为八进制表示,反之亦然的最佳方法是什么
- 如何使系统在十六进制数之前打印 0x,在八进制数之前打印 0?
- 如何在C++中使用setiosflags打印出十进制数作为八进制数
- 用于"Ctrl + left arrow"和"Ctrl + right arrow"的八进制代码
- 八进制文字怎么可能是负数?
- 图形面积(等分三角形、正方形、五角形、六边形、七重奏、八进制)使用 if-else (C++)
- 将八进制分数转换为十进制 - c++
- 我如何使用动态内存分配将小数转换为八进制
- 将八进制字符串转换为C 中的小数线
- 为什么 fcntl() 标志值以八进制格式定义,以及此函数如何用于阻塞/非阻塞套接字?
- 八进制到十进制的转换(调试)
- 在 c++ 中将八进制数变成实数
- C++二进制转换为十进制,八进制
- 声明变量时编译器错误 - 八进制序列 200 254 342
- 将声明的 INT/UINT 的八进制/十六进制分配给另一个变量