社区讨论

为什么我的程序不能跑?

P8761[蓝桥杯 2021 国 BC] 大写参与者 5已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@m24tdtl2
此快照首次捕获于
2024/10/11 22:19
去年
此快照最后确认于
2025/11/04 17:24
4 个月前
查看原帖
直接上代码
CPP
#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;
}
为啥编译不成功 报错信息如下:
CPP
/tmp/compiler_nxfichnc/src:14:24: 错误:程序中有游离的‘\35714 |             ascii -= 32;
      |                        ^
/tmp/compiler_nxfichnc/src:14:25: 错误:程序中有游离的‘\27414 |             ascii -= 32;
      |                         ^
/tmp/compiler_nxfichnc/src:14:26: 错误:程序中有游离的‘\23314 |             ascii -= 32;
      |                          ^
/tmp/compiler_nxfichnc/src: 在函数‘int main()’中:
/tmp/compiler_nxfichnc/src:9:21: 警告:comparison of integer expressions of different signedness: ‘intand ‘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 ‘char14 |             ascii -= 32;
      |                        ^
      |                        ;
   15 |             char currentChar = (char) ascii;
      |             ~~~~        
/tmp/compiler_nxfichnc/src:16:20: 错误:‘currentChar’在此作用域中尚未声明
   16 |             a[i] = currentChar;
      |                    ^~~~~~~~~~~
为什么会这样呢? 跪求大神指点!

回复

4 条回复,欢迎继续交流。

正在加载回复...