我是新的數組,我在這裏寫了這段代碼,我認爲我已經正確完成了所有語法。但是,我得到一個字符串未聲明的標識符
C2065「串」:未聲明的標識符
正如你可以看到我有我的原型設定,但它仍然給出了錯誤?
#include<iostream>
#include<string>
//Prototypes:
void getJars(string[], int[], int);
int getTotal(string[], int[], int);
using namespace std;
int main() {
string salsa[] = { "Mild", "Medium", "Sweet", "Hot", "Zesty" };
const int NUM = 5;
int jars[NUM];
getJars(salsa, jars, NUM);
getTotal(salsa, jars, NUM);
return 0;
}
void getJars(string salsa[], int jars[], int NUM) {
cout << "Salsa Sales Calulator...\n";
cout << "------------------------\n";
for (int i = 0; i < NUM; i++) {
cout << "Please Insert the Jar Amount for Each Salsa: ";
cout << salsa[i];
cout << " ";
cin >> jars[i];
cout << endl;
}
return;
}
int getTotal(string salsa[], int jars[], int NUM) {
int total;
for (int i = 0; i < NUM; i++) {
total += jars[i];
}
return total;
}
我擡起頭,對這裏的錯誤,但是,他們已經拿出瞭解決方案,以增加其中大部分人忘記了,但是我沒有忘記的原型,它仍然給出了錯誤?誰能幫忙?
只是'#include'會爲您解決這個問題。 –
在原型之前放置'using namespace std;'。 –
@ MoeAbdul-Hameed:或者將該類型稱爲「std :: string」。 –