如何忽略istream字符串的
How to ignore for istream strings
有没有人对我如何忽略来自istream的"n"有任何建议?我试图从文本文件中提取数据,其中在一些"单元格"中,文本已经写入,当用户按下Enter时,会出现"n"。
我的目标是接收文本的某些部分,并使用";"把各个部分分开。然而,在这样做时,有时会吸入"n",并且输出单元格开始继续向下,而不是从右到左(这是首选)。
任何建议将不胜感激!
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);
}
您可以使用此命令从字符串中删除所有n
:
mainString.erase(std::remove(mainString.begin(),mainString.end(),'n'),mainString.end());