给大家出道题
读数据文件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编辑过]