Hello guys, i've just registered and i hope to find a fast solution.
my job is to read in a master data file of several persons.
this data should be display by a winform gui...
this is the structure of the file is
id;surname;forename;size;sex
1;mustermann;max;1.95;m
now my problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
// PersonalVerwaltung.cpp: Hauptprojektdatei.
#include "stdafx.h"
#include "Form1.h"
#include "Person.h"
#include <vector>
using namespace PersonalVerwaltung;
void readPersonsFromFile(vector<CPerson>*);
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Aktivieren visueller Effekte von Windows XP, bevor Steuerelemente erstellt werden
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
//personList =
vector<CPerson>* personList= new vector<CPerson>;
readPersonsFromFile(personList);
// Hauptfenster erstellen und ausführen
Application::Run(gcnew Form1(personList));
return 0;
}
void readPersonsFromFile(vector<CPerson> *t_PersonList)
{
/* Funktioniert mit direkter Zuweisung
CPerson *t_Person = new CPerson(1, "Mustermann", "Max",1.95, "m");
t_PersonList->push_back(*t_Person);
t_Person = new CPerson(1, "Musterfrau", "Birgit",1.73, "w");
t_PersonList->push_back(*t_Person);*/
/**Variante mit auslesen aus Datei****************************************/
int i = 0; //Laufindex für Auslesen
char buffer[150];
FILE *f;
f=fopen("Personal.txt","r");
for(i=0;fgets(buffer,sizeof buffer,f)!=NULL;i++)
{
t_PersonList->push_back(*new CPerson(atoi(strtok(buffer,";")),
strtok(NULL,";"),
strtok(NULL,";"),
atof(strtok(NULL,";")),
strtok(NULL,";")));
}
}
|
if i code it like this, the vector is full of one data -->only one person in every row...in debuggin mode, i see, that in every row the addresses for every property is the same...
i've tried to avoid this by taking
|
t_PersonList->push_back(*new CPerson(atoi(strtok(buffer,";")), ...etc.
|
any suggestions?
and the second problem is:
in the main method i'm creating a vector personList--> this is given to the reader-method by "call by reference"
nethertheless the temporary t_personList is filled all with the same data...
the "main" personList has the same contents except the char-fieds...
in debugging mode there is ""
my latin is over...
hope you can understand me :-)
aah i forgot...i'm using visual studio 2010