S(=1+1-1-1+1…)の結果をanswer変数を使わず,countで表示させることはできないのでしょうか.
・入力文字列の0,2,4,……文字目には1が書いてあることを前提とする
・入力文字列の1,3,5,……文字目の記号(+か-)に応じて計算を行なう
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int count=0;
for (int i = 0; i < S.size(); i++) {
if (S.at(2i+1) == '+') { count++;}
else if (S.at(2i+1) == '-') {count--;}
}
cout << count<< endl;
}
ですが,エラーが生じてしまいます.
./Main.cpp:10:21: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
10 | for (int i = 0; i < S.size(); i++) {
| ~~^~~~~~~~~~
どこがおかしいのか分からないので教えてください.