有沒有人對我怎麼能夠無視「\ n」的任何建議,由istream的未來嗎?我試圖從txt文件中提取數據,其中某些「單元格」中的文本已經寫入,使得當用戶按下Enter時出現「\ n」。如何忽略istream的字符串 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);
}
你應該使用常量&和與您的函數參數。你不能只使用string :: find和string :: erase在你的輸入字符串中刪除'\ n'的所有出現? – UldisK
@UldisK你爲什麼這麼說? – ktosayev
你提到用戶輸入enter並且被吸入。也許這跟使用istream :: getline()一樣簡單? http://www.cplusplus.com/reference/istream/istream/getline/ 它的默認delim是'\ n',它會丟棄它。 –