R
das ist mein erstes wenn man es nennen darf "programm" in c++
bin für verbesserungs vorschläge gerne zu ohr
ich habe erstmal auf prüfungen verzichtet soweit es geht es soll ja erstmal mal nur einfügen und löschen .. der rest kommt dann später
#include <string>
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[]) {
//Anzahl der Parameter ausgeben
const std::string stradd = "add";
const std::string strremove = "remove";
string s;
//Jeden einzelnen Übergabeparameter ausgeben
for (int i=0; i < argc; i++) {
if (argc<2){
cout << "try --help for more info" << endl;
return 0;
}
//else {
if (stradd == argv[i]) {
cout << "adding values..." << endl;
ifstream in("Neelix_tables.gm"); // Open for reading
ofstream out("Neelix_tables2.gm"); // Open for writing
while(getline(in, s)) // Discards newline char
if (s.find ("//Admins") != string::npos){
out << "//Admins" << "\n";
out << "" << "\n";
out << "{name=\"" <<argv[2]<< "\",cl_guid=\"" <<argv[3]<< "\",admin_level=" <<argv[4]<< ",admin_pw=\"" <<argv[5]<< "\",}," << "\n"; // ... must add it back
}
else{
out << s << endl; // ... must add it back
}
}
if (strremove == argv[i]) {
cout << "adding values..." << endl;
ifstream in("Neelix_tables.gm"); // Open for reading
ofstream out("Neelix_tables2.gm"); // Open for writing
while(getline(in, s)) // Discards newline char
if (s.find (argv[2]) != string::npos){
out << "" ;//<< "\n";
//out << "" << "\n";
//out << "{name=\"" <<argv[2]<< "\",cl_guid=\"" <<argv[3]<< "\",admin_level=" <<argv[4]<< ",admin_pw=\"" <<argv[5]<< "\",}," << "\n"; // ... must add it back
}
else{
out << s << endl; // ... must add it back
}
}
//}
}
ifstream FileInCopy("Neelix_tables2.gm", ios::binary);
// Zieldatei
ofstream FileOutCopy("Neelix_tables.gm", ios::binary);
if (FileInCopy)
FileOutCopy << FileInCopy.rdbuf();
if( remove( "Neelix_tables2.gm" ) != 0 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );
return 0;
}
die textdatei sieht so aus:
/*///////////////////////////////////////////////////////////////////////////////////////////////////////
AdminList:
*////////////////////////////////////////////////////////////////////////////////////////////////////////
global AdminList={
//Admins
{name="Arthur Dent",cl_guid="1234abc",admin_level=3,admin_pw="",},
//Friend(s)
{name="TheGamer", cl_guid="1234abc",admin_level=1,admin_pw="",},
};
danke für eure hilfe
gruss ren22