Question

Does anyone have any suggestions on how I can ignore the "\n" coming in from istream? I'm trying to extract data from txt file where in some "cells", text has been written in such that there are "\n" coming in from when the user pressed Enter.

My goal is to take in some parts of this text and output it with " ; " separating the parts. However, in doing so, sometimes a "\n" gets sucked in and the output cell starts continuing downwards instead of just line going from right to left (which is preferred).

Any advice would be much appreciated!

string vectorToString(vector<size_t> positionVector, string mainString,
                                      string outputString, int numLetters)

{
    //Check how many different positions were found and make that the length
    //of the vector that will store all the strings for each finding
    int positionVectorLength = positionVector.size();
    //foundPos is the position of the cursor along the foundPositions vector
    int vectorPosition=0;
    while (vectorPosition < positionVectorLength)
    {
        //define local variable that will store the value along the vector
        size_t vectorPositionValue = positionVector.at(vectorPosition);


        //append the numLetters after the positionValue in string frameNum
        outputString.append(mainString, vectorPositionValue, numLetters);
        outputString.append(" ; ");     

        //reiterate until all the positions have been recorded
        vectorPosition+=1;
    }

    //return the string of frame numbers
    return(outputString);
}
Était-ce utile?

La solution

You can use this to remove all the \n from your string:

mainString.erase(std::remove(mainString.begin(),mainString.end(),'\n'),mainString.end());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top