#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
void vowel(fstream a){
char ch;
int ctr = 0;
while(!a.eof()){
a.get(ch);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){
cout << ch;
ctr++;
}
}
cout << "Number of Vowels: " << ctr;
}
main(){
fstream a;
a.open("temp.txt", ios::in);
vowel(a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在这个简单的程序中,我试着计算temp.txt文件中的元音数量.但是,我收到错误:
在函数fstream :: fstream(fstream&)中无法访问ios :: ios(ios&)
而是在函数本身中打开文件来完成工作.为什么会这样?非常感谢
注意:
在这里它说,它应该按我尝试的方式工作.
干草堆
这是一个程序,我试图multi::multi(int, int)在函数中调用类构造函数void multi::multiply().输出是
三十
三十
而不是预期的
三十
25
为什么?
#include <iostream.h>
class multi{
private:
int a;
int b;
public:
multi(int m, int n){
a = m;
b = n;
}
void multiply(){
cout << "\n\n" << a*b;
multi (5, 5);
cout << "\n" << a*b;
}
};
main(){
multi x(5,6);
x.multiply();
return 0;
}
Run Code Online (Sandbox Code Playgroud)