C++从文件中按照单词读取内容
程序员文章站
2022-03-08 13:41:21
...
读取方式: 逐词读取, 词之间用空格区分,遇到"."就停止读取,返回的内容存取在vector中
//read data from the file, Word By Word //when used in this manner, we'll get space-delimited bits of text from the file //but all of the whitespace that separated words (including newlines) was lost. //http://www.sharejs.com vectorReadDataFromFileWBW() { ifstream fin("Input.txt"); string strWord(""); vector v; while( fin >> strWord ) { //字符串string类的比较要用compare函数 if (strWord.compare(strWord.length()-1, 1, ".") == 0) { strWord.erase(strWord.length()-1, 1); v.push_back(strWord); return v; } v.push_back(strWord); } }
上一篇: php ajax分页代码
下一篇: 一款简单的php 文件上传源码