schnelle Hilfe bei Bibliothek benötigt



  • Ich habe folgendes Program:

    #include <stdlib.h>
    #include <stdio.h>
    #include <string>
    #include<iostream>
     #include<fstream>
    #include<vector>
    
    using namespace std;
    
    class kontaktlist
    {
    public:
    ifstream is;
    ofstream off;
    
    	kontaktlist(char* begin,char *neu) {
     		readlist(begin);
       		writelist(begin,neu);
      		clearlist(begin,neu);
    	}
    
    	vector<string> readlist (char *begin){
    	        vector<string>foo_r;
    	        string end=".c";
    	        string all = begin + end;
    	  	char *next_r = &all.at(0);
    		is.open(next_r,ios::in);
    		  if (is.is_open())
    		  {
    			is.seekg (0, ios::end);
      		  	int length_r = 0;
    		  	length_r = is.tellg();
      		  	is.seekg (0, ios::beg);
    		  	char *buffer_r = new char[length_r];
    			is.read (buffer_r,length_r);
    		  	is.close();
    			foo_r.push_back(buffer_r);
    			return (foo_r);
    		  	}else{
    			is.close();
    			off.open(next_r,ios::out|ios::app);
    			off<<"";
    			off.close();
    			return (foo_r);
    		}
    	}
    
    	void writelist (char *begin,string neu){
    		string end=".c";
    	        string all = begin + end;
    	  	char *next_w = &all.at(0);
    	    	is.open(next_w,ios::in);
    		if (is.is_open())
      		{
    			is.close();
    			off.open(next_w,ios::out|ios::app);
        			neu= neu + ';';
    		    	char *neu_w = &neu.at(0);
    			off<<neu_w;
        			off.close();
      		}else{
    			is.close();
    			off.open(next_w,ios::out|ios::app);
    			off<<"";
    			off.close();
    		}
    	}
    
    	void clearlist(char *begin_c,char *name){
    		int i=0;
    		int anz=0;
    		string end_c =".c";
    		string all_c = begin_c + end_c;
    		char *next_c = &all_c.at(0);
    		is.open(next_c,ios::in);
    		if(is.is_open()){
    			is.seekg (0, ios::end);
      			int length_c = 0;
    			length_c = is.tellg();
    			char vor[length_c];
      			is.seekg (0, ios::beg);
    			//Abfangschleife:Datei ist leer
    			if(length_c==0)
    			{
    				is.close();
    			}else{
    				char *buffer_c = new char[length_c];
    				is.read (buffer_c,length_c);
    				memcpy(vor,buffer_c,length_c);
    				for(int k= 0;k<length_c;k++)
    				{
    					if(vor[k]==';')
    					{
    						anz++;
    					}
    				}
    				string foo_c[anz];
    				for(int h= 0;h<length_c-1;h++)
    				{
    					if(vor[h]==';')
    					{
    						i++;
    					}else{
    						foo_c[i] +=vor[h];
    					}
    
    			 	}
    				bool kontr= false;
    				for(int j=0;j<i;j++)
    				{
    				  	if(foo_c[j]== name)
    					{
    						for (int l=j; l<i;l++)
    				    		{
    							foo_c[l]=foo_c[l+1];
    						}
    					kontr=true;	
    					}
    				}
    				//Kontrallschleife: eigegebener Benutzer existiert nicht in der Kontaktliste
    				if(kontr== false)
    				{
    					is.close();
    				}else{
    				 	is.close();
    				 	off.open(next_c,ios::out);
    				 	for(int l= 0;l<i-1;l++)
    					{
    				 		off<<foo_c[l];
    						off<<';';
    				 	}
    				 	off.close();
    				}
    			}
    		}else{
    			//Datei existiert nicht und wirde deshalb erzeugt
    			is.close();
    			off.open(next_c,ios::out|ios::app);
    			off<<"";
    			off.close();		
    		}
    	}
    
    };
     int main(){
        kontaktlist test("cat","hallo");
        return 0;
     }
    

    versucht in eine Libary umzuwandeln:
    siehst du hier:
    http://www.rafb.net/paste/results/5lT5mF57.html
    hab ich das so richtig gemacht?? (ist mein first try)
    bitte um Antworten.Thx.


Anmelden zum Antworten