为什么程序一直报错啊

P1723 高手过愚人节

```cpp /* Author: EnderDeer Online Judge: Luogu */ #include<bits/stdc++.h> #define int long long #define mem(x) memset(x,0,sizeof(x)) using namespace std; int read(){ int s = 0,w = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')w = -1;ch = getchar();} while(ch >= '0' && ch <= '9')s = s * 10 + ch - '0',ch = getchar(); return s * w; } int a; string s; signed main(){ cin>>a>>s; for(int i = 1;i <= s;i ++){ int ans; ans ++; } cout<<ans; return 0; } ```
by EDqwq @ 2021-04-01 11:30:24


草这不是我们昨天模拟赛原题吗![jk](https://cdn.luogu.com.cn/upload/pic/62234.png)
by houpingze @ 2021-04-01 11:31:15


是您自己的问题吧,我这里是彩虹色的啊
by LeavingZ @ 2021-04-01 11:31:50


你每次循环都定义了一遍ans,没赋值,还++?
by 天有不测风云 @ 2021-04-01 11:31:58


s定义为string类型,又i <= s
by 天有不测风云 @ 2021-04-01 11:32:52


@[天有不测风云](/user/109217) 好好看看cppReference!变量初值明明处处为0!!1
by LeavingZ @ 2021-04-01 11:33:05


@[天有不测风云](/user/109217) 我们老师说过,你在使用一个int和string比较的时候会强制转换的啊???????
by EDqwq @ 2021-04-01 11:33:54


@[林深时x见鹿](/user/294562) 就说样例,"aaaaa"能转换成什么?
by 天有不测风云 @ 2021-04-01 11:35:06


@[天有不测风云](/user/109217) aaaaa的长度是5,不应该是5吗? 那ans变量每次加1,最后不应该是5吗?为什么没有通过样例,甚至报错啊!!!!!
by EDqwq @ 2021-04-01 11:35:59


这道题看似很难,其实就是输出输入的字符串的长度,我观察出来了,证明略,你们用那种难的方法,我简直是无语了,我这种方法代码短并且正确
by EDqwq @ 2021-04-01 11:36:53


| 下一页