为什么我的程序不能跑?
查看原帖
为什么我的程序不能跑?
1473968
CodingTim楼主2024/10/11 22:18

直接上代码

#include<bits/stdc++.h>

using namespace std;

int main()
{
    string a;
    cin >> a;
    for(int i = 0;i < a.size();i++)
    {
        if(a[i] >= 'a' && a[i] <= 'z')
        {
            int ascii = (int)a[i];
            ascii -= 32char currentChar = (char) ascii;
            a[i] = currentChar;
        }
    }
    cout << a << endl;
    return 0;
}

为啥编译不成功 报错信息如下:

/tmp/compiler_nxfichnc/src:14:24: 错误:程序中有游离的‘\357’
   14 |             ascii -= 32;
      |                        ^
/tmp/compiler_nxfichnc/src:14:25: 错误:程序中有游离的‘\274’
   14 |             ascii -= 32;
      |                         ^
/tmp/compiler_nxfichnc/src:14:26: 错误:程序中有游离的‘\233’
   14 |             ascii -= 32;
      |                          ^
/tmp/compiler_nxfichnc/src: 在函数‘int main()’中:
/tmp/compiler_nxfichnc/src:9:21: 警告:comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    9 |     for(int i = 0;i < a.size();i++)
      |                   ~~^~~~~~~~~~
/tmp/compiler_nxfichnc/src:14:24: 错误:expected ‘;’ before ‘char’
   14 |             ascii -= 32;
      |                        ^
      |                        ;
   15 |             char currentChar = (char) ascii;
      |             ~~~~        
/tmp/compiler_nxfichnc/src:16:20: 错误:‘currentChar’在此作用域中尚未声明
   16 |             a[i] = currentChar;
      |                    ^~~~~~~~~~~

为什么会这样呢? 跪求大神指点!

2024/10/11 22:18
加载中...