bygger på det Robert skrev.
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char ** argv) {
ofstream out("filnavn.txt");
if (out.is_open()) {
out << "Navn: Farmor" << endl;
out << "Telefonnummer: 97920000" << endl;
out << "Adresse: Alderdomhjemmet"<< endl;
out << "AdresseNr: 666"<< endl;
out << "By: gammelby"<< endl;
out << "Postk: 0000"<< endl;
out << "Navn: Mormor" << endl;
out << "Telefonnummer: 97920000" << endl;
out << "Adresse: Alderdomhjemmet2"<< endl;
out << "AdresseNr: 432"<< endl;
out << "By: nyby"<< endl;
out << "Postk: 2600"<<endl;
//...osv.
}
out.close();
ifstream in("filnavn.txt");
char oneline[255];
string navn;
int nummer;
if(in.is_open()) {
while(!in.eof()){
in.getline(oneline,255,'\\n');
if(in.eof()){break;}
navn=oneline;
navn.replace(0,6,"");
cout<<navn<<endl;
in.getline(oneline,255,'\\n');
sscanf(oneline,"Telefonnummer: %d",&nummer);
cout<<nummer<<endl;
in.getline(oneline,255,'\\n');
navn=oneline;
navn.replace(0,9,"");
cout<<navn<<endl;
in.getline(oneline,255,'\\n');
sscanf(oneline,"AdresseNr: %d",&nummer);
cout<<nummer<<endl;
in.getline(oneline,255,'\\n');
navn=oneline;
navn.replace(0,4,"");
cout<<navn<<endl;
in.getline(oneline,255,'\\n');
sscanf(oneline,"Postk: %d",&nummer);
cout<<nummer<<endl;
}
}
return 0;
}