Main:
Código:
#include <iostream>
#include <fstream>
#include <string.h>
#include<string>
#include<stdio.h>
#include <stdlib.h>
#include "info.hh"
#define MAX_CUSTOMERS 30
using namespace std;
int main(){
info group[MAX_CUSTOMERS]();
info aux();
int index = 0;
int proba;
int i =0;
string read_line;
ifstream myfile ("30");
if (myfile.is_open())
{
while ( getline (myfile,read_line) )
{
aux(read_line);
group[i] = aux;
i++;
}
myfile.close();
proba = group[i].getNumber;
cout << proba << endl;
}
else{
cout << "Unable to open file";
}
return 0;
}
Header:
Código:
#include <iostream>
#include <fstream>
#include <string.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
class info {
public:
info(string);
int getNumber();
private:
int phone;
char *name, *email, *city;
};
Clase
Código:
#include <iostream>
#include <fstream>
#include <string.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include "info.hh"
using namespace std;
info::info(string line) {
char s[line.size()+1];
strcpy(s,line.c_str());
char *token = strtok(s,",");
name = token;
token = strtok(NULL,",");
city=token;
token = strtok(NULL,",");
email=token;
token = strtok(NULL,",");
phone= atoi (token);
}
int info::getNumber(){
return phone;
}
Archivo con strings:
Código:
Josep A.,Tarragona,josep@yahoo.com,658347774
Jan Q.,Tarragona,jan@gmail.com,634172596
Jordi R.,Paris,jordi@hotmail.com,676384167
Jaume R.,Barcelona,jaume@yahoo.com,633985748
Jaume R.,Barcelona,jaume@hotmail.com,669975576
Joana Y.,Munic,joana@yahoo.com,606391524
Joana Q.,Lleida,joana@gmail.com,602392390
Josep T.,Munic,josep@yahoo.com,672911438
Joana Y.,Girona,joana@hotmail.com,658187802
Joan C.,Paris,joan@yahoo.com,678281912
Jordina E.,Lleida,jordina@gmail.com,665082493
Joan J.,Paris,joan@hotmail.com,607992054
Jana S.,Tarragona,jana@gmail.com,679064408
Jordina H.,Paris,jordina@yahoo.com,608418282
Joana T.,Munic,joana@yahoo.com,604402400
Jana I.,Girona,jana@hotmail.com,674395941
Joan V.,Munic,joan@gmail.com,666538693
Jana P.,Munic,jana@hotmail.com,687860264
Josep W.,Tarragona,josep@hotmail.com,615823273
Jordina I.,Lleida,jordina@hotmail.com,665168337
Jordina K.,Munic,jordina@hotmail.com,675734247
Joana Z.,Paris,joana@hotmail.com,605532569
Jaume D.,Tarragona,jaume@hotmail.com,694269478
Jordina V.,Girona,jordina@yahoo.com,615466633
Josep B.,Munic,josep@yahoo.com,627358944
Jordi C.,Paris,jordi@yahoo.com,619503102
Jan N.,Tarragona,jan@hotmail.com,690374509
Jordina H.,Tarragona,jordina@hotmail.com,663157753
Joana Z.,Girona,joana@gmail.com,657528666
Jaume H.,Girona,jaume@hotmail.com,614992694
ERROR:
Código:
main.cc: In function ‘int main()’:
main.cc:12:28: error: declaration of ‘group’ as array of functions
main.cc:23:17: error: too many arguments to function ‘info aux()’
main.cc:13:7: note: declared here
main.cc:24:4: error: ‘group’ was not declared in this scope
main.cc:28:11: error: ‘group’ was not declared in this scope