我是新的数组,我在这里写了这段代码,我认为我已经正确完成了所有语法。但是,我得到一个字符串未声明的标识符
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”。 –