我已经为此工作了2个多小时。我已将我的问题隔离为一段代码。
问题出在我的阵列上。它正在输出非常大的负值。我输入数组的值是正确的。我对 java 有经验,但这是我的第一个 C++ 程序。
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(){
string inputString;
cin >> inputString;
cout << inputString << endl;
int mainArray[10];
for(int x = 0; x < inputString.length(); x++){
int valFound = inputString[x]-48; //minus 48 to change from ascii to int
mainArray[valFound]++;
cout << mainArray[valFound];
}
return 0;
}
任何帮助将不胜感激,这让我发疯。