Continuous writing text effect - String issues

Hey there,

I am trying to create a program which continually loads characters of a piece of text. when the test is of a certain height it should then delete the first line and continue to load in more characters. I seem to be getting some bugs with drawing as this gets stuck inside the delete part of the update function.

I then realised I should use pos on the substr command to then go from line 2 of the main text to the end.

I am now getting this issue with the drawing https://youtu.be/76kk4EvuAew

drawString = code.substr( pos, ofMap(time, 0.0, timeToTakeToType, 0, code.length()-1 ));
size_t remove_first_line(std::string& s) {
    
    int pos = 0;
    if(auto idx = s.find('\n'); idx != std::string::npos) {
        s.erase(s.begin(), std::next(s.begin(), idx+1));
        pos = idx;
    }
    
    return pos;
}

void update(){

    // Delete first line
    if (font->height(drawString) > ofGetHeight()/4 )
    {
        pos = remove_first_line(drawString);
    }
   
    // Add new Characters
    float timePerLetter = 0.002;
    float timeToTakeToType = code.length() * timePerLetter;
    float time = ofGetElapsedTimef();
    time = fmodf( time, timeToTakeToType);
    drawString = code.substr( pos, ofMap(time, 0.0, timeToTakeToType, 0, code.length()-1 ));
}

void draw(){
    ofBackground(0);
    
    ofSetColor(255);
    ofDrawBitmapString("FPS:" + ofToString(ofGetFrameRate()), ofGetWidth() - 100, 0);
    font->draw(drawString, 0, 50);
}

Apparently, it was my silly mistake in that I was including the newline character at when exectuing s.find('\n'). so this made the text gitter up and down. ha