0

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);
}
4

1 回答 1

0

您可以使用它\n从字符串中删除所有内容:

mainString.erase(std::remove(mainString.begin(),mainString.end(),'\n'),mainString.end());
于 2013-06-05T12:47:24.183 回答