本来我是用string_array.find(item)
搜索的,但是编译器说没有。
然后我搜索看看是否可以使用string_array->find(item)
指针来解决问题,但没有任何解释。
这是我的代码:
#include<iostream>
#include<string>
using namespace std;
string name [100];
int Jan[100]={0}, Feb[100]={0}, Mar[100]={0}, Apr[100]={0}, May[100] = 0, Jun[100]={0},Jul[100]={0}, Aug[100]={0},Sep[100]={0},Oct[100]={0},Nov[100]={0},Dec[100]={0};
int earning [100];
int main () {
ifstream load;
load.open("record.txt");
if(load.fail()){
cout << "error in loading data" << endl;
exit(1);
}
else {
int i = 0;
string NAME;
int EARNING;
int MONTH;
int dump1;
char dump2;
while ( load.eof() != 1 ) {
int n = 0;
load >> NAME >> EARNING >> dump1 >> dump2 >> MONTH >> dump2 >> dump1 ;
n = name->find(NAME);
if ( n < 0 ) {
n = i ;
}
else {
i = i - 1 ;
}
name[n] = NAME;
if ( MONTH == 1) { Jan[n] += EARNING ;}
if ( MONTH == 2) { Feb[n] += EARNING ;}
if ( MONTH == 3) { Mar[n] += EARNING ;}
if ( MONTH == 5) { Apr[n] += EARNING ;}
if ( MONTH == 5) { May[n] += EARNING ;}
if ( MONTH == 6) { Jun[n] += EARNING ;}
if ( MONTH == 7) { Jul[n] += EARNING ;}
if ( MONTH == 8) { Aug[n] += EARNING ;}
if ( MONTH == 9) { Sep[n] += EARNING ;}
if ( MONTH == 10) { Oct[n] += EARNING ;}
if ( MONTH == 11) { Nov[n] += EARNING ;}
if ( MONTH == 12) { Dec[n] += EARNING ;}
i++;
}
}
}