0

I'm at the start of writing a csv-file parser for a file with around 8000 Ids. When running, after around half the Ids are read and printed, the Clion console starts overwriting the first outputs so that at the end of running the first Id in my consoles output is the 2626th instead of the first. What in my code is responsible for this?

When printing every read character before the switch starts, the output is complete. It also works with a smaller amount of Ids, when i shorten the amount in the csv to around 6000.

int main() {

string buffer;
char zeichen;
ifstream eingabe;
eingabe.open("../lib/Daten.csv");
int zustand=0;//0=Token, 1=Werte

if(eingabe){
    while(!eingabe.eof()) {
        eingabe.get(zeichen);
        //cout<<zeichen; // with only this it works
        switch(zeichen){
            case';':
                if(zustand==0){
                    cout<<"Token: "<<buffer<<"; ";
                }
                else if(zustand==1){
                    cout<<"Wert: "<<buffer<<"; ";
                }
                buffer="";
                break;
            case'\n':
                if(zustand==0){
                    zustand=1;
                    cout<<"Token: "<<buffer<<endl;
                }
                else if(zustand==1){
                    cout<<"Wert: "<<buffer<<endl;
                }
                buffer="";
                break;
            default:
                buffer+=zeichen;
                break;
        }
    }

}
eingabe.close();

   return 0;
}
Jidko
  • 3
  • 4
  • Sounds like a Clion thing. Try writing a simpler program that just outputs 8000 lines of text, see if you get the same problem. – Paul Sanders Feb 04 '19 at 12:35
  • First please read [Why is iostream::eof inside a loop condition considered wrong?](https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) Then unless this is for an exercise or school (or similar) assignment, *don't* try to create a CSV parser yourself, use an existing library instead. While CSV files might seem easy to parse, it contains a lot of corner- and special-cases that makes it very hard and non-trivial to create a generalized parser. – Some programmer dude Feb 04 '19 at 12:36
  • As for your problem, have you tried to [flush](https://en.cppreference.com/w/cpp/io/basic_ostream/flush) `std::cout`? – Some programmer dude Feb 04 '19 at 12:38
  • @PaulSanders i have tried simply outputting the lines without parsing them in any special way and then all lines get printed. – Jidko Feb 04 '19 at 12:42
  • @Someprogrammerdude thank you, it is for a school project. I will try to flush and read your link – Jidko Feb 04 '19 at 12:43
  • 1
    Definitely test the output in a regular terminal before assuming it's your code. I've seen the Clion terminal do some weird things. – Mike Borkland Feb 04 '19 at 12:44
  • @MikeBorkland Thank you for the suggestion, it really seems to be Clion, when printing into another file everything is there! – Jidko Feb 04 '19 at 12:57
  • Did you try this: [Override console cycle buffer size](https://stackoverflow.com/questions/7836313/how-to-stop-intellij-truncating-output-when-i-run-a-build)? – uta Feb 06 '19 at 08:15

1 Answers1

0

Answered by all the helpful people in the comments. It seems to be connected to Clion

Jidko
  • 3
  • 4
  • Definitely so. Memory is a very valuable resource. But the console buffer size can be changed in the settings. – uta Feb 06 '19 at 08:30
  • Did you try this: [Override console cycle buffer size](https://stackoverflow.com/questions/7836313/how-to-stop-intellij-truncating-output-when-i-run-a-build)? – uta Feb 06 '19 at 10:01
  • Cool idea, i'll try that! Thank you – Jidko Feb 06 '19 at 16:01