Toll, nun sieht alles korrekt aus, aber funktionieren tut's dennoch nicht -.-
Vielleicht kennt sich ja einer von euch damit aus... wie ich korrekt das doofe USC-2 File lesen kann. Hier der Code:
Code:
// LogReader.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <dirent.h>
#include <locale> /* for locale */
using namespace std;
void fixencoding(string instring)
{
string outstring;
ofstream outf;
outf.open("all.xml", ios_base::app);
int i = 0;
while (i < instring.length()){
if (i % 2 == 1){
outf << instring[i];
}
i++;
}
outf.close();
}
int main()
{
string line, last_line, last_lastline;
string filename, extension;
size_t pos;
char file[255];
char folder[] = "./logs/";
ofstream outfile;
outfile.open("all.xml");
outfile << "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
outfile << "<?xml-stylesheet href=\"itemlog.xsl\" type=\"text/xsl\"?>\n";
outfile << "<itemlog>\n";
outfile.close();
DIR *pDIR;
struct dirent *entry;
if( pDIR=opendir("./logs/") ){
while(entry = readdir(pDIR)){
if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 )
{
filename = entry->d_name;
pos = filename.length() - filename.find(".xml");
cout << pos << endl;
strcpy(file,folder);
strcat(file,entry->d_name);
cout<<file<<endl;
if (pos == 4)
{
ifstream myfile (file);
if (myfile.is_open())
{
getline (myfile,line);
if (myfile.good())
getline (myfile,line);
if (myfile.good())
getline (myfile,line);
if (myfile.good())
getline (myfile,line);
last_line = line;
if (myfile.good())
getline (myfile,line);
while(myfile.good())
{
last_lastline = last_line;
last_line = line;
getline (myfile,line);
fixencoding(last_lastline);
outfile.open("all.xml", ios_base::app);
outfile << endl;
outfile.close();
}
myfile.close();
}
else cout << "Unable to open file\n";
}
}
}
closedir(pDIR);
}
outfile.open("all.xml", ios_base::app);
outfile << "</itemlog>";
outfile.close();
system("pause");
return 0;
}
Oder weiss einer wie ich's hinbekomm, dass die Log files direkt in UTF-16 gespeichert werden?