逐字读取文本文件时如何忽略"end of line"或"new line"字符?
How can I ignore the "end of line" or "new line" character when reading text files word by word?
目标:
我正在逐字读取文本文件,并将每个单词保存为数组中的元素。然后我逐字打印出这个数组。我知道这可以更有效地完成,但这是为了一个任务,我必须使用数组。
我正在对数组做更多的事情,例如计算重复的元素、删除某些元素等。我还成功地将文件转换为完全小写且没有标点符号。
现状:
我有一个文本文件,如下所示:
beginning of file
more lines with some bizzare spacing
some lines next to each other
while
others are farther apart
eof
<小时 />这是我的一些代码,itemsInArray
在0
初始化,并引用为wordArray[ (approriate length for my file ) ]
的单词数组:
ifstream infile;
infile.open(fileExample);
while (!infile.eof()) {
string temp;
getline(infile,temp,' '); // Successfully reads words seperated by a single space
if ((temp != "") && (temp != 'n') && (temp != " ") && (temp != "n") && (temp != "