从文本文件一次读取一个单词 [英] Reading one word at a time from text file

查看:165
本文介绍了从文本文件一次读取一个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何一次从一个文本文件中读取一个单词,该单词之间用空格隔开.指针也应随之移动.我的意思是我不想在阅读一行后使用String.split方法.我想阅读单词并将单词插入文件中的特定位置.

How do i read one word at a time from a text file in which the words are separated by a white space. The pointer should also move along. I mean i dont want to use the String.split method after reading a line. I want to read words and insert a word at a particular position in the file. Is there a simple way to do this??

推荐答案

StreamReader具有一次每次读取一个字符的Read()方法.使用(缓冲版本 [
StreamReader has a Read() method that reads one character at a time. It might be more efficient to use the (buffered version[^]) at the cost of getting a few extra characters and more complexity but getting one char at a time is slow.

All you then need do is loop, checking each each char in turn.



只需逐行读取并使用
将其标记在空间上 < pre lang ="c ++"> arr = strtok(buffer,'''');</pre>

从Internet检查正确的语法.
arr将带有单词.
Hi,
Just read line by line and token it on space using
<pre lang="c++">arr = strtok(buffer,'' '');</pre>

check the correct syntax from internet.
arr will have the words.


这篇关于从文本文件一次读取一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆