C++ 无法检测到ASCII码

C++ 无法检测到ASCII码,c++,visual-c++,C++,Visual C++,用于检测负数 #include <string> #include <iostream> #include <cmath> using namespace std; string command; getline(cin,command); if (command[0] == '-') encoder = -1; #包括 #包括 #包括 使用名称空间std; 字符串命令; getline(cin,命令); 如果(命令[0]=='-') 编

用于检测负数

#include <string>
#include <iostream>
#include <cmath>
using namespace std;

string command;
getline(cin,command);

if (command[0] == '-')
        encoder = -1;
#包括
#包括
#包括
使用名称空间std;
字符串命令;
getline(cin,命令);
如果(命令[0]=='-')
编码器=-1;
用于点的检测

  else if (command[x] == '.')
        {
            if (detector = 0)
            {
                floater = pow(10, -1 * x);
                detector = 1;
            }
            else
            {
                cout << "You have typed the wrong word or format.\n";

                return 0;
            }
        }
else if(命令[x]='.)
{
如果(检测器=0)
{
浮子=功率(10,-1*x);
检测器=1;
}
其他的
{

cout您发布的代码不是真正的代码,但是
setlocale
调用的省略可能反映了真正代码中类似的省略

这就是要做的一件事,在
main
的开头添加一个
setlocale(LC_ALL,“”)
调用

您还应该注意修剪(删除不需要的空白)输入字符串,并检查之后是否还有任何字符

此外,在

if (detector = 0)
很可能是打字错误

自由使用
const
有助于避免这种情况,也有助于避免(在我看来,这是一种误导,因为它降低了可读性)在比较中先编写常量的做法


此外,使用整数作为布尔值,而不是像您所做的那样使用
bool
类型,这是一种不好的做法。

command[0]的值是多少
?粘贴足够的代码,以便我们编译代码,提供与您相同的输入,并复制错误。请显示更多上下文;
x
的定义是什么?如果(检测器=0)有错误,至少表达式
getline(cin,command);
在函数之外是非法的。请发布真实代码。