为什么我的 int 在 C++ 程序中间发生变化?

why my int change in the middle of c++ programm?

我写了下面的代码。问题是这样的:在我从输入流中读取 xy 之后就没有关系了 - 意思是 xy 是输入的确切值 - 但后来他们更改为其他值。

怎么了?看不懂!!

int count(char s[], char ss[] , long long int posF, long long int posE){}
int main()
{
    char s[]{};
    int q = 0;
    cin >> s;
    cin >> q;
    int choise = 0;
    while(q--)
    {
        cin>>choise;
        if(choise == 1)
        {
            int x = 0;
            cin>>x;
            char c;
            cin>>c;
            s[x-1] = c;
        }
        else if(choise == 2)
        {
            int x = 0;
            int y = 0;
            cin>>x>>y;
            //Fist LOG
            cout<<"First log x and y are correct    "<<x<<"  "<<y<<endl;
            char ss[]{};
            cin>>ss;
            //Second LOG
            cout<<"Second log x and y are  wrong?Why?"<<x<<"  "<<y;
            cout<<count(s, ss, x-1, y-1)<<endl;
        }

    }
    return 0;
}

正如对方所说,你的代码的问题是char ss[]{};cin>>ss;所以如果你评论你会理解它

所以我的建议是使用字符串而不是 char[],你可以使用 cin<< 作为字符串,你可以使用 [] 运算符 e.x

string s = "Code";
cout<<s[0];

和M.r @Ron 是正确的最好阅读This Books