当前位置: 代码迷 >> C语言 >> 给大家出道题
  详细解决方案

给大家出道题

热度:183   发布时间:2004-10-15 12:38:00.0
给大家出道题
读数据文件a.txt,统计其中元音大写字母出现的次数,去掉空格后,生成新文件new.txt.
----------------解决方案--------------------------------------------------------
他简单了吧,使用文本读取,就可以了嘛
----------------解决方案--------------------------------------------------------

/*除了空格没有删掉以外,其他完成了,刚学的方法没多久,各位高手多指教*/

#include <fstream> #include <iostream> #include <string>

using namespace std;

int main() { ifstream infile("a.txt"); ofstream outfile("new.txt"); string word; char c; int count=0; while(infile>>word) { for(int i=0;i<word.length();i++) if(word[i]=='A'||word[i]=='E'||word[i]=='I'||word[i]=='O'||word[i]=='U') count++; outfile<<word; infile.get(c); outfile.put(c); } cout<<"the number of the vowel is "<<count<<"."<<endl; return 0; }

[此贴子已经被作者于2004-10-18 15:18:01编辑过]


----------------解决方案--------------------------------------------------------
空格好象是'23',有的编译器用'40',自己试到行为止吧。
----------------解决方案--------------------------------------------------------
三少爷,你二哥和大哥怎么没上论坛啊?呵呵
----------------解决方案--------------------------------------------------------
  相关解决方案