をスタックトレースを示すが、Netbeansの実行は、スタックトレースを出力C++プログラムが正常に、何も出力を構築していない、唯一正常にビルド
スタックトレース:
Frame Function Args
0022C694 7570EFA3 (00000108, 0000EA60, 00000000, 0022C7B8)
..............
End of stack trace
私は、ファイルの行ごとのチェックを読んでいますC++クラスの概念を使用している母音を持っている場合。
私はファイルを1行ずつ読み込んでテストし、C++クラスを使用せずに1行ずつファイルを正常に書き込むことができました。
私のコードを変更する必要があることを指摘してください。私はメモリ管理の問題があると思う。
ありがとうございました!
#include <cstdlib>
#include<fstream>
#include <iostream>
using namespace std;
class Password{
private:
char *pwd;
public:
Password(const char*pwd){
setPassword(pwd);
}
~Password(){
delete []pwd;
}
void setPassword(const char *pwd){
delete []this->pwd;
if(pwd!=NULL){
this->pwd=new char[strlen(pwd)+1];
strcpy(this->pwd,pwd);
}else{
this->pwd=NULL;
}
}
char *getPassword(){
return this->pwd;
}
bool containsVowel(){
int i,counter=0;
for(i=0;i<strlen(this->pwd);i++){
if(this->pwd[i]== 'a' || 'e' || 'i' || 'o' || 'u')
counter++;
}
if (counter>0)
return true;
return false;
}
};
int main(int argc, char** argv) {
ifstream infile("C:/Users/user/Desktop/say.in");
ofstream outfile("C:/Users/user/Desktop/say.out");
string str;
while (getline(infile,str)){
const char *pwd=str.c_str();
Password pwdObj(pwd);
if (pwdObj.containsVowel()==true){
outfile<<"<"<<str<<"> is accpetable\r\n";
}
}
infile.close();
outfile.close();
return 0;
}
ここでは、ほとんどの場合、メモリ管理の問題があります。あなたは破壊時に 'delete'を実行しますが、' new'(あるいは 'NULL'へのポインタをinit!)しないでください。コピーコンストラクタ/ op ='はありません。 RAIIと3のルールについて読んでください。そして、 'std :: string'に何か問題がありますか? –